<!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>
<script src="../vue.js"></script>
<style>
.test{
width: 100px;
height: 100px;
background-color: red;
}
</style>
</head>
<body>
<div id="app">
{{name}}
{{num}}
<button @click='add'>add</button>
<button @click='change'>change</button>
</div>
<script>
let vm=new Vue({
el:'#app',
data:{
num:1,
name:'韩梅梅'
},
methods:{
add(){
this.num++
},
change(){
this.name='lileilei'
}
},
watch:{
num:(newValue,oldValue)=>{
console.log('你变了');
console.log("new",newValue);
console.log("old",oldValue);
},
name:()=>{
console.log('你变了');
},
}
})
</script>
</body>
</html>
|