methods方式数据不会缓存,每次加载到页面上都需要重新计算
watch:有两个值,新值和旧值
computed值会缓存,
methods只适合用于业务逻辑处理,数据不会缓存
watch只适合监听单个数据
computed适合监听多个数据,可以缓存计算的值方便下次使用
案列1
<!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>
<!--1.导入Vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>
</head>
<body>
<div id="app">
<p>currentTime1:{{currentTime1()}}</p>
<p>currentTime2:{{currentTime2}}</p>
</div>
<script>
var vm=new Vue({
el:"#app",
data:{
message:"pan"
},
methods:{
currentTime1:function(){
return Date.now();
}
},
computed:{
currentTime2:function(){
this.message;
return Date.now();
}
}
})
</script>
</body>
</html>