const app = Vue.createApp({
data(){
return{
message:'hello world',
count:3,
price:6,
}
},
watch:{
price(){
setTimeout(() => {
console.log('price changed')
}, 3000);
}
},
computed:{
total(){
return Date.now() + this.count
}
},
methods:{
methodstotal(){
return Date.now()
}
},
template:`
<div>{
{ message }} {
{ total }}</div>
`
}).mount('#root');
当在浏览器控制台输入
app.$data.price=‘1000’
“1000”
price changed
watch监听器有current,pr