<template>
<view>
<view style="height: 100px;width: 100px;background-color: yellow;" @click="clickTop">
</view>
<input type="text" placeholder="文本输入键盘" v-model="buttontext" />
</view>
</template>
<script>
export default {
data() {
return {
itemList: [1, 2, 3, 4] as Array<number>,
buttontext: 'xxx'
}
},
watch: {
buttontext(newValue, oldValue) {
console.log("buttontext:", newValue);
},
itemList(newValue, oldValue) {
console.log("itemList:", newValue);
}
},
methods: {
clickTop() {
console.log('clickTop');
// this.itemList.push(3)//通过此方法修改无法监听到
// this.itemList[3] = 10;//通过此方法修改无法监听到
this.itemList = [2] //这样就可以监听到改变
this.buttontext = 'sada'
},
}
}
</script>
<style>
</style>
1 个回复
爱豆豆 - 办法总比困难多
加上deep即可 需要深度监听