猿问

vue 后台返回的数据有些是通过枚举得到的数字,页面上要怎么展示这些数据代表的文字信息?

仓库名称
仓库类型
仓库备注
{{item.WarehouseName}}
{{item.WarehouseType}}
{{item.WarehouseDesc}}
js代码:
data(){
return{
warehouses:[
{"WarehouseId":1,"WarehouseType":1,"WarehouseName":"深圳仓库","WarehouseDesc":"深圳仓库",
},
{"WarehouseId":2,"WarehouseType":2,"WarehouseName":"东莞仓库","WarehouseDesc":"东莞仓库",
}]
}
},
}
其中WarehouseType是枚举算法得到的数值,1代表“默认仓库”,2代表“自建仓库”,现在页面上要怎么样操作能把1和2代表的文字信息展示出来,比如:WarehouseType是1的时候,table中绑定的WarehouseType就展示“默认仓库”4个字?
莫回无
浏览 6324回答 2
2回答

largeQ

在data中创建一个枚举的json对象WarehourseTypeName:{'1':'默认仓库','2':'自建仓库'}调用{{WarehourseTypeName[item.WarehouseType]}}

繁星淼淼

也可以使用filters,代码如下:html:{{item.WarehouseName|toText}}{{item.WarehouseType|toText}}{{item.WarehouseDesc|toText}}js:data(){return{warehouses:[{"WarehouseId":1,"WarehouseType":1,"WarehouseName":"深圳仓库","WarehouseDesc":"深圳仓库"},{"WarehouseId":2,"WarehouseType":2,"WarehouseName":"东莞仓库","WarehouseDesc":"东莞仓库"}]}},filters:{toText(val){switch(val){case1:return"默认仓库";case2:return"自建仓库";default:return"";}}}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答