html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<script src="../vue/vue.js">script>
head>
<body>
<div id="root">
<h2>今天天气很{{info}}h2>
<button @click="changeWeather">切换天气button>
div>
body>
<script type="text/javascript">
Vue.config.productionTip= false
const vm=new Vue({
el:'#root',
data:{
isHot:true
},
computed:{
info(){
return this.isHot ?"hot":"cold"
}
},
methods:{
changeWeather(){
this.isHot=!this.isHot
}
},
watch:{
isHot: {
handle(newValue,oldValue){
console.log('hhhh',newValue,oldValue)
}
}
}
})
script>
html>
代码拼写错误了。
监听中的 单词 应为 ‘handler’,而不是 ‘handel’,改为这样即可:
isHot: {
handler(newValue,oldValue){
console.log('hhhh',newValue,oldValue)
}
}