当前位置:网站首页>Common function writing method and set get writing method for calculating attributes
Common function writing method and set get writing method for calculating attributes
2022-07-02 06:42:00 【indulge...】
characteristic :
- When defining , To be defined as “ Method ”
- When using calculated attributes , When ordinary attributes are used
- Calculation properties cache the results of the calculation , Only when the data on which the calculation attribute depends changes , Before the operation is repeated
benefits :
- Realize the reuse of code
- As long as the dependent data source in the calculation attribute changes , The calculated property is automatically re evaluated !
Common writing
<template>
<div>
<p> And for : {
{ num }}</p>
<p>{
{ reverseMessage }}</p>
</div>
</template>
<script> export default {
data() {
return {
a: 10, b: 20, message: " I'm a string ", }; }, computed: {
num() {
return this.a + this.b; }, reverseMessage() {
return this.message.split("").reverse().join(""); }, }, }; </script>
Complex writing
<template>
<div>
<div> Gender is :{
{
getsex}}</div>
<button @click="addarr"> add to </button>
<div> change name Value {
{
getname}}</div>
</div>
</template>
<script>
export default {
name: "newsdetail",
data(){
return{
sex:[' male ',' Woman '],
first: 'wang',
two: 'kun'
}
},
computed: {
// Each calculated attribute includes a getter(get) And a setter(set)
// The function filled in the calculation attribute is equivalent to the abbreviation get
getsex:function (){
// Calculate the return It can't be less
return this.sex[0]
},
getname:{
get: function () {
console.log(' Called fullName Of get Method ');
return this.first + ' ' + this.two;
},
// Only when getname It can only be triggered when the value in changes set, Value transmitting value yes getname Changed value
set: function (value) {
console.log(' Called fullName Of set Method ',value);
const names = value.split(' ');
this.first = names[0];
this.two= names[1];
}
}
},
methods:{
addarr:function (){
this.getname='jiang ke'
}
}
}
</script>
<style scoped>
</style>
边栏推荐
猜你喜欢

Win10: add or delete boot items, and add user-defined boot files to boot items

Find the highest value of the current element Z-index of the page

Redis——缓存击穿、穿透、雪崩

Detailed definition of tensorrt data format

默认google浏览器打不开链接(点击超链接没有反应)

Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)

CTF web practice competition

一口气说出 6 种实现延时消息的方案

查询GPU时无进程运行,但是显存却被占用了

Name six schemes to realize delayed messages at one go
随机推荐
Vector types and variables built in CUDA
js中正则表达式的使用
Usage of map and foreach in JS
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Redis - big key problem
Pytest (2) mark function
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
Redis——缓存击穿、穿透、雪崩
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
Blog directory of zzq -- updated on 20210601
AWD learning
Pytest (1) case collection rules
automation - Jenkins pipline 执行 nodejs 命令时,提示 node: command not found
查询GPU时无进程运行,但是显存却被占用了
FE - Eggjs 结合 Typeorm 出现连接不了数据库
Dynamic global memory allocation and operation in CUDA
Function execution space specifier in CUDA
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
ctf-web之练习赛