vue -- computed & watch

computed to calculate property

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0">  <meta http-equiv="X-UA-Compatible" content="ie=edge">  <title>计算属性</title></head><body>  <h1>计算属性</h1>  <br>  <div id="app">    {{newPrice}}  </div>  <script src="../js/vue.js"></script>  <script type="text/javascript">    var app = new Vue({      el: "#app",      data: {        price: 100,      },      computed: {        newPrice() {          return this.price = '¥' + this.price + '元'        }      },    })  </script></body></html>复制代码

Calculating attribute 
 1 is a function, the function name to call directly in page
 2 must return a value return 
 . 3 can be calculated simultaneously a plurality of attributes 

watch listen properties
in 

watch (){}复制代码

 Data in the data name as the function name, and the return value is needed, each attribute may only listen to one


Two different

Computing a plurality of data values ​​may be calculated at the same time, a listener can listen only data value


Reproduced in: https: //juejin.im/post/5d070429e51d457756536792

Guess you like

Origin blog.csdn.net/weixin_33928467/article/details/93173024