vue-java-tutorials/vue2-tutorials/import-script/9-监视属性.html

40 lines
842 B
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../js/vue@2.7.16.js"></script>
<title>监视属性</title>
</head>
<body>
<div id="app">
<h2>天气很什么:{{isHot}}</h2>
<button @click="changeWeather">切换天气</button>
</div>
</body>
<script>
const vm = new Vue({
el: "#app",
data: {
isHot: true
},
methods: {
changeWeather() {
this.isHot = !this.isHot
}
},
watch: {
immediate: true,
isHot: {
handler(newVal, oldVal) {
console.log("值修改", newVal, oldVal);
}
}
}
})
</script>
</html>