其他分享
首页 > 其他分享> > vue3计算属性

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,
    };
  },
};

 

标签:return,computed,firstName,newName,lastName,person,计算,vue3,属性
来源: https://www.cnblogs.com/alannero/p/15463424.html