在项目里写一个二级联动,省份列表中每一项有个children,里面是市列表。在做下拉列表的时候我是这样书写的。其中provinceList是省列表 ,cityList是市列表
computed: {
cityList: function () {
return this.provinceList.filter((item) => {
return this.info.province == item.value;
}.children);
},
},
之后vue会直接报错,猜测是因为第一个return使用后不能直接接children。之后我把这个属性修改到了watch里就成功修复了bug。不知道有没有大神有别的解决方法
info: {
handler: function (newVal, oldVal) {
this.provinceList.forEach((item) => {
if (item.name === newVal.province) {
this.cityList = item.children;
}
});
},
immediate: true,
deep: true,
},