Vue2 监听属性改变watch
来源:互联网 发布:js集合和数组 编辑:程序博客网 时间:2024/06/11 15:34
效果:
代码:
<div id="app2"> <label>幼儿园入学年龄(3~6):</label><input type="number" v-model="child.age"> <button @click="older"> + </button> <button @click="younger"> - </button> <p v-show="hasErr">{{ errMsg }}</p></div><script> var app = new Vue({ el:"#app2", data:{ child:{age:2}, hasErr:false, errMsg:"" }, methods:{ older:function () { this.child.age ++; }, younger:function () { this.child.age --; }, hideErr:function () { var self = this; setTimeout(function () { self.hasErr = false; },3000); } }, //构造器内的watch watch:{ 'child.age':function (newVal,oldVal) { if(newVal > 6){ this.child.age = 6; this.errMsg = "不得大于6岁"; this.hasErr = true; this.hideErr(); } } } }); app.$watch("child.age", function (newVal,oldVal) { if(newVal < 3){ app.child.age = 3; app.errMsg = "不得小于3岁"; app.hasErr = true; app.hideErr(); } }, {deep:true, immediate:true}); //deep默认true immediate指示是否立即以表达式的当前值触发回调</script>
阅读全文
0 0
- Vue2 监听属性改变watch
- vue1.0和vue2.0的watch监听事件写法
- 监听属性的改变
- angularJS $scope的$watch方法监听model改变
- vue2.0+watch()
- vue2.0监听数组中对象属性的变化
- Angular中使用$watch监听object属性值的变化
- KVO-对象属性值改变监听
- Swift——监听属性的改变
- GO ZK WATCH监听
- angular的watch监听
- Zookeeper Watch监听
- vue-watch 深度监听!!
- Vue2.0的改变
- Vue2.0的改变
- vue2.0学习笔记 ——watch
- vue2 中 computed 和 watch 的异同?
- vue(2) -- vue在watch中监听对象属性的变化
- Dubbo 简单的应用Dubbo+Zookeeper+Spring整合
- 图形学算法与相应的源码-帮助你重复的造三维图形学以及三维可视化领域的轮子
- PyTorch基本用法(一)——Numpy,Torch对比
- SQL四种语言:DDL,DML,DCL,TCL
- 完美解决python3.6环境下,使用pyinstaller打包.exe时报错的情况。
- Vue2 监听属性改变watch
- DES算法
- hdc1000 linux下驱动
- 蓝牙开发网址记录
- 抓包工具+Access注入
- 多继承小记
- map
- echarts3 柱状图数字在柱的顶部显示
- spring data es拼音插件