当前位置:网站首页>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>
边栏推荐
- Basic operations of objects
- 第二部分—C语言提高篇_9. 链表
- DHCP, VLAN, NAT, large comprehensive experiment
- Question 152: product maximum subarray
- Everything you should know about wearable NFT!
- Push to origin/master was rejected error resolution
- Upload files to OSS file server
- Embedded system migration [8] - device tree and root file system migration
- 力扣155题,最小栈
- Pyqt5 how to set pushbutton click event to obtain file address
猜你喜欢

文件上传到服务器

第3章 跨域问题

Part II - C language improvement_ 9. Linked list
![[shader realizes swaying effect _shader effect Chapter 4]](/img/ab/bdbc4a0f297541b532af81a49e2633.png)
[shader realizes swaying effect _shader effect Chapter 4]

Real time voice quality monitoring

New features of ES6

Part II - C language improvement_ 7. Structure

Public cloud security and compliance considerations

18、打开、保存文件对话框使用小记

Add an article ----- scanf usage
随机推荐
Part II - C language improvement_ 5. Bit operation
Hcip day 2_ HCIA review comprehensive experiment
org.yaml.snakeyaml.scanner. ScannerException: mapping values are not allowed here in ‘reader‘, line
Disk expansion process and problems encountered in the virtual machine created by VMWare
18. Opening and saving file dialog box usage notes
NFT display guide: how to display your NFT collection
Everything you should know about wearable NFT!
[C language] array
Azure Synapse Analytics 性能优化指南(3)——使用具体化视图优化性能(下)
Easily implement seckill system with redis! (including code)
大疆智图、CC生产了多份数据,如何合并为一份在图新地球进行加载
Sign up now | frontier technology exploration: how to make spark stronger and more flexible
MVC three-tier architecture
【不积跬步无以至千里】统计日志指定时间段内的关键词
关于可穿戴式NFT你应该知道的一切!
Positioning of soaring problems caused by online MySQL CPU
MySQL syntax uses detailed code version
C language dynamic memory management
Dynamic SQL
Three person management of system design