vue的计算属性

vue的计算属性 computed计算

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div id="app">
    {{message}}
  <h2>{{firstName + lastName}}</h2>
  <h2>{{firstName}} {{lastName}}</h2>
  <h1>{{getfullName()}}</h1>
  <h3>{{fullName}}</h3>
</div>
<script src="../vue.js"></script>
<script>
  const app = new Vue({
    el: '#app',
    data: {
      message: 'hello',
      firstName: 'Cai',
      lastName: 'heng'
    },
    methods: {
      getfullName() {
        return this.firstName + ' ' + this.lastName
      }
    },
    computed:{
      fullName(){
        return this.firstName + ' ' + this.lastName
      }
    }
  })
</script>
</body>
</html>
  • 计算属性就是让它变成属性。本质上是实现了,计算属性的get方法
原文地址:https://www.cnblogs.com/ch2020/p/14819403.html