1 properties
这里有两个属性 options和modelValue,对modelValue进行监听
父组件两个属性都传了值
properties: { options: { // 选项数组 type: Array, value: [], }, modelValue: { // 默认选中的 type: String, value: "", observer: function () { //如果有默认值,需要匹配出name,所以这里使用obersver,当父组件中值改变时触发 this.handleData(); } }, },
2 监听函数
handleData() { console.log('this.properties前',this.properties) console.log('this.properties.options',this.properties.options) console.log('this.properties后',this.properties) }
打印的情况如下图
前后两条打印出来的properties里面的options都是有值的,就是中间打印出来的数组是空的,非常奇怪
3 处理
最后没办法,智能在options也加上监听
实例看:https://www.cnblogs.com/jthr/p/19157667