文章目錄
- 126. python進階------vue(6)
-
-
- python修煉第二十九天
- 2019年 4月 29日 晴
-
126. python進階------vue(6)
python修煉第二十九天
2019年 4月 29日 晴
監聽屬性
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./vue.min.js"></script>
<script>
window.onload = function () {
new Vue({
el: "#app",
data: {
num: 0
},
methods: {
func1: function () {
this.num += 1
}
},
watch: { // 用于設定要監聽的屬性
num: function () { // 當num屬性發生變化時, 會調用該匿名函數
// vue屬性變化時, 會先觸發監聽, 再更新界面
if (this.num > 9){
this.num = 111
}
}
},
})
}
</script>
</head>
<body>
<div id="app">
{{num}}<br/>
<button @click="func1">按鈕</button>
</div>
</body>
</html>