当前位置:网站首页>10_ Name Case - Calculation attribute
10_ Name Case - Calculation attribute
2022-07-26 23:52:00 【ID does not exist.】
Name Case - Compute properties
Compute properties :
1. Definition : The attribute to use does not exist , To calculate from existing properties
2. principle : The bottom layer has the help of Object.defineproperty Method getter and setter
3.get When does the function execute ?
(1) The first read is performed once
(2) When the dependent data changes, it will be called again
4.get What's the role ?
When someone reads fullName when ,get It will be called , And the return value is as fullName Value
5. advantage : And methods Realize the comparison , There is an internal caching mechanism ( spare ), More efficient , Debug is convenient
6. remarks :
(1) The calculated properties will eventually appear in vm On , Directly read and use
(2) If the calculation property is to be modified , That must be written set Function response modification , And set To cause the data that the calculation depends on to change .
<body>
<div id="root">
surname :<input type="text" v-model="firstName"> <br /><br />
name :<input type="text" v-model="lastName"> <br /><br />
full name :<span>{
{fullName}}</span> <br /><br />
</div>
</body>
<script type="text/javascript">
const vm = new Vue({
el: '#root',
data: {
firstName: ' Zhang ',
lastName: ' 3、 ... and ',
},
// Complete writing
computed: {
fullName:{
get(){
console.log('get Is called the ')
return this.firstName + '-' + this.lastName
},
set(value){
console.log('set',value)
const arr = value.split('-')
this.firstName = arr[0]
this.lastName = arr[1]
}
}
})
</script>
<body>
<div id="root">
surname :<input type="text" v-model="firstName"> <br /><br />
name :<input type="text" v-model="lastName"> <br /><br />
full name :<span>{
{fullName}}</span> <br /><br />
</div>
</body>
<script type="text/javascript">
Vue.config.productionTip = false // prevent vue Generate production prompts at startup .
const vm = new Vue({
el: '#root',
data: {
firstName: ' Zhang ',
lastName: ' 3、 ... and ',
},
computed: {
// Abbreviation
fullName() {
return this.firstName + '-' + this.lastName
}
}
})
</script>
边栏推荐
- Meeting OA project seating function and submission function
- 实数范围内的求模(求余)运算:负数求余究竟怎么求
- Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)
- Use Arthas to locate online problems
- Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management
- NFT display guide: how to display your NFT collection
- Lesson 2 of Silicon Valley classroom - building project environment and developing lecturer management interface
- Vit:vision transformer super detailed with code
- Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
- Tensorflow2.0 deep learning simple tutorial of running code
猜你喜欢
随机推荐
Pytorch learning record (II): tensor
Vit:vision transformer super detailed with code
第1章 拦截器入门及使用技巧
公有云安全性和合规性方面的考虑事项
Kingbasees database administrator's Guide -- 11 manage data files and temporary files
【2016】【论文笔记】差频可调谐THz技术——
分页插件--PageHelper
Product principles of non-financial decentralized application
Concept of functional interface & definition and use of functional interface
证券公司哪家佣金最低?网上开户安全吗
04-传统的Synchronized锁
[C language] array
[shader realizes swaying effect _shader effect Chapter 4]
Application of workflow engine in vivo marketing automation | engine 03
简单的SQL优化
Typescript notes
【C语言】数组
[interview: concurrency 26: multithreading: two-phase termination mode] volatile version
Differences between PHP round and sprintf functions
力扣152题:乘积最大子数组









