<div id="app">
  {{fullName}}
  {{age}}
  <hr>
  <button @click="count">计算属性缓冲机制,当计算的内容没有发生变化时,页面重新渲染的时候不会重新进行计算渲染该元素/控制台只会在运行的时候打印1次</button>
  <br><br>
  <button @click="upName">计算属性缓冲机制,当计算的内容发生变化时,页面重新渲染的时候会重新进行计算渲染该元素/控制台会在运行的时候再次打印1次</button>
</div>
var app = new Vue({
  el: "#app",
  data: {
    firstName: "xiao",
    lastName: "dongxier",
    age: "28"
  },
  // 计算属性,内置缓存
  computed: {
    fullName: function () {
      console.log("计算了1次");
      return this.firstName + " " + this.lastName;
    }
  },
  methods: {
    count: function () {
      this.age++;
    },
    upName: function () {
      this.firstName += "xiao";
    }
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/vue/2.7.8/vue.min.js