当前位置: 代码迷 >> 综合 >> VUE----computed watch
  详细解决方案

VUE----computed watch

热度:21   发布时间:2023-12-13 16:53:00.0
<!DOCTYPE html>
<html lang="en"><head><meta charset="UFT-8"><title>vue</title><script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
</head><!-- 计算属性: computed侦听器: watch使用场景: watch(异步场景) computed(数据联动)-->
<body><div id="app">{
   {msg}}<p>{
   {msg1}}</p></div><script>var arr = 'new test'// 将vue赋值给一个变量就可以在控制台调试vuevar app = new Vue({el: '#app',data: {msg: 'hello vue!',another: 'another Hello Vue!'},methods: {},watch: {msg: function (newval, oldval) {console.log('newval is ' + newval)console.log('oldval is ' + oldval)}},computed: {msg1: function () {// 由 msg + another 组成的 msg1 在 vue实例中任意一个值变化 都会影响到msg1 return 'computed:' + this.msg + ',' + this.another + arr}},})</script>
</body>
</html>

 

  相关解决方案