使用ui组件时 深拷贝的用法
在使用ui组件时 有时会因为组件限定的数据名称 需要修改 数据的名字 这时就需要使用深拷贝
//在使用 uview 下拉菜单时
<u-dropdown-item v-model="value1" title="综合" :options="options1" :disabled="true"></u-dropdown-item>
//下拉组件识别的 数据参数名必须是 label 和 value 所以就要使用深拷贝 修改参数名称
options1: [{
label: '价格由高到低',
value: 1,
},
{
label: '价格由低到高',
value: 2,
},
],
//修改参数名称实例
let newArr = JSON.parse(JSON.stringify(res.filterCategory).replace(/name/g, "label").replace(/id/g, "value"))
//res.filterCategory 所修改的数据
//.replace(/name/g, "label") 将数据中的名字为name 改为 label 后面同理