vue3计算属性

import { reactive, computed } from "vue";
export default {
  name: "HelloWorld",
  setup() {
    let person = reactive({
      firstName: "李",
      lastName: "晓玲",
    });
    //计算属性简写(没有考虑计算属性被修改被修改的情况)
    person.fullName = computed(() => {
      return person.firstName + person.lastName;
    });
    //计算属性完整写法
    /*person.fullName = computed(()=>{
      get(){
        return person.firstName + '-'+ person.lastName
      },
      set(value){
        const newName = value.split('-')
        person.firstName = newName[0]
        person.lastName = newName[1]
      }
    })*/
    return {
      person,
    };
  },
};

 

上一篇:Vue 之虚拟 DOM 及 Diff 算法详解


下一篇:Vue-diff算法详解