vue 使用watch 侦听数据变化动态执行函数
// 由父组件传来的值 model & onLineModelListprops: {model: {type: Object,required: true},onLineModelList: {type: Array,required: true}},// 监听 onLineM...
·
// 由父组件传来的值 model & onLineModelList
props: {
model: {
type: Object,
required: true
},
onLineModelList: {
type: Array,
required: true
}
},
// 监听 onLineModelList 如果发生变化则执行方法
watch: {
// 注意: function (newQuestion, oldQuestion) 这个形参是写死的
onLineModelList: function (newQuestion, oldQuestion) {
for (var a = 0; a < newQuestion.length; a++) {
if (this.model.imId !== null && this.model.imId !== '' && this.model.imId === newQuestion[a].imId) {
this.model.realUserCount = newQuestion[a].onLineUserCount
}
}
}
},
methods: {
更多推荐
已为社区贡献10条内容
所有评论(0)