1 计算属性
<body>
<div id="app">
函数获取时间: {{getCurrentTime()}}
<br>
计算属性获取时间:{{getCurrentTime1}}
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
},
methods:{
getCurrentTime:function (){
return new Date();
}
},
computed:{
getCurrentTime1:function (){
return new Date();
}
}
})
</script>
2 watch
<body>
<div id="app">
{{title}}
<input type="text" v-model="title">
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
title:"Hello Vue",
},
watch:{
title: function (newValue,oldValue){
console.log("new: ",newValue," ,old:",oldValue)
}
}
})
</script>
转载请注明原文地址:https://tech.qufami.com/read-5594.html