watch侦听器
语法:
new Vue({
el:'',
data:{
要监听的值:''
},
methods:{},
wathch:{
//参数一:改变后的值.
//参数二:改变前的值.
要监听的值(newValue,oldValue){
}
}
})
示例:
<!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>Document</title>
</head>
<body>
<div id="app">
<button @click="msg = '你好' ">修改msg</button>
<p>{
{msg}}</p>
</div>