您的位置:首页 > 新闻 > 资讯 > 广东网站制作报价_上海国际进出口贸易博览会_seo工资多少_bing搜索 国内版

广东网站制作报价_上海国际进出口贸易博览会_seo工资多少_bing搜索 国内版

2024/10/13 14:49:35 来源:https://blog.csdn.net/qq_58341172/article/details/142883070  浏览:    关键词:广东网站制作报价_上海国际进出口贸易博览会_seo工资多少_bing搜索 国内版
广东网站制作报价_上海国际进出口贸易博览会_seo工资多少_bing搜索 国内版

模板界面:

<template><div class="person"><h2>姓: <input type="text" v-model="person.firstName" /></h2><h2>名: <input type="text" v-model="person.lastName" /></h2><button @click="changeFullName">修改全名</button><h2>全名:<label>{{ fullName }}</label></h2><h2>全名:<label>{{ fullName }}</label></h2></div>
</template>

计算属性的使用:
 

<script setup name="computedName">import {reactive,toRefs,computed} from 'vue'const person = reactive({firstName:'张',lastName:'三'})const {firstName,lastName} = toRefs(person)
// 计算属性 默认是只读的 有缓存
// const fullName = computed(() =>{
//     console.log("1");
//     return firstName.value.slice(0,1).toUpperCase() + firstName.value.slice(1) + '-' + lastName.value.slice(0).toLowerCase()
// })// 计算属性 默认是只读的 有缓存
const fullName = computed({get(){console.log("1");return firstName.value.slice(0,1).toUpperCase() + firstName.value.slice(1) + '-' + lastName.value.slice(0).toLowerCase()},set(val){console.log("2");console.log('set',val);const [str1,str2] = val.split('-')firstName.value = str1lastName.value = str2}
})//该方法只是引起computed 中 set方法的调用
function changeFullName(){fullName.value = 'aaa-bbb'console.log(fullName.value);
}
</script>

样式:

<style scoped>
.person {background-color: #ccc;padding: 10px;border-radius: 10px;box-shadow: 0 0 10px;
}
</style>

注意:computed包含缓存,与方法不同,并且computed可以赋新值

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com