<template>
<view>
<!-- <view class="font">{{name}}</view> -->
<view class="font">{{num}}</view>
<view class="font">{{num>10?'优秀':''}}</view>
<button type="primary" @tap="change()">修改</button>
</view>
</template>
<script>
export default {
data() {
return {
name:"我是一个名称",
num:0
}
},
watch:{
name:function(val) { //监听的字段需要和data里面声明得字段一样,才能够实现监听效果。
console.log(val)
},
num:function(val){
console.log(val);
}
},
methods:{
change:function(){
// this.name="被修改了";
this.num++;
}
}
}
</script>
<style>
.font{
font-size: 50upx;
}
</style>
VUE watch用法展示
原创
©著作权归作者所有:来自51CTO博客作者成都阿信的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:uniapp 获取当前屏幕的高度
下一篇:uniapp 事件和阻止冒泡
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Vue3 中的监听 watch
Vue3 中的监听 watch
Vue3 watch监听 -
VUE中watch的写法和用法
两种写法都可以实现在检测到rw的值变化时,进行调用里面的方法。
vue.js 前端 javascript 人工智能 -
vue watch
Vue.js已在全球开发人员中广受欢迎,这归功于其灵活的响应式系统和丰富的开发工具。本文将深
vue.js 前端 javascript Vue 解决方案 -
vue 的watch用法
1、普通的watch 2、数组的watch 3、对象的watch 4、对象具体属性的watch[活用computed]
vue 数组 i++ #include