解决模板中复杂的逻辑运算以及复用的问题
const App = {
  data() {
    return {
      studentCount: 1
    }
  },
  template: `
    <h1>{{ studentCount > 0 ? ('学生数:' + studentCount) : '暂无学生' }}</h1>
  `
}
Vue.createApp(App).mount('#app');
避免多次计算,只要data下属性不改变,只会计算一次,也就是缓存
const App = {
  data() {
    return {
      studentCount: 1
    }
  },
  template: `
    <h1>{{ studentCountInfo }}</h1>
    <h1>{{ studentCountInfo }}</h1>
  `,
  computed: {
    studentCountInfo() {
      console.log('Invoked');
      return this.studentCount > 0
                            ? ('学生数:' + this.studentCount)
                            : '暂无学生';
    }
  }
}
Vue.createApp(App).mount('#app');

const vm = new Vue({
  data() {
    return {
      name: 'Lance',
      age: 28
    }
  },
  computed: {
    // 默认为 getter
    getName() {
      return this.name;
    },
    // getter、setter 配合使用
    ageData: {
      get() {
        return this.age;
      },
      set(newVal) {
        this.age = newVal;
      }
    }
  }
});