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方法
posted @ 2021-05-27 19:13  竹石2020  阅读(34)  评论(0编辑  收藏  举报