想要监听那个属性,就在watch中编写对应属性的方法即可
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>监听器</title>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div id="app">
<input v-model="store" type="number">
</div>
</body>
</html>
<script>
var app = new Vue({
el: "#app",
data:{
store: 0
},
watch:{
//监听store属性
store(){
if(this.store >= 3){
alert("超出库存")
}
}
}
})
</script>
标签:app,watch,52,监听器,store,属性
From: https://www.cnblogs.com/morehair/p/17026140.html