当前位置:网站首页>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>
边栏推荐
- Error "list" object is not callable in Web automatic switching window
- ctf三计
- Storage space modifier in CUDA
- Redis——大Key问题
- Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
- Win10: add or delete boot items, and add user-defined boot files to boot items
- 浏览器滚动加载更多实现
- QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
- 奇葩pip install
- Solution to the black screen of win computer screenshot
猜你喜欢

Redis - grande question clé

Sparse array (nonlinear structure)

Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved

The default Google browser cannot open the link (clicking the hyperlink does not respond)

Redis - cluster data distribution algorithm & hash slot

Utilisation de la carte et de foreach dans JS

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

Usage of map and foreach in JS

Learn about various joins in SQL and their differences

unittest. Texttestrunner does not generate TXT test reports
随机推荐
Eggjs -typeorm treeenity practice
ctf-web之练习赛
JS modification element attribute flipping commonly used in selenium's Web Automation
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
Win电脑截图黑屏解决办法
[daily question 1] write a function to judge whether a string is the string after the rotation of another string.
(the 100th blog) written at the end of the second year of doctor's degree -20200818
20201002 VS 2019 QT5.14 开发的程序打包
实现strStr() II
20201025 Visual Studio2019 QT5.14 信号和槽功能的使用
Usage of map and foreach in JS
CUDA and Direct3D consistency
Cglib agent - Code enhancement test
一口气说出 6 种实现延时消息的方案
NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
CTF three count
Shardingsphere JDBC
[literature reading and thought notes 13] unprocessing images for learned raw denoising
浏览器滚动加载更多实现
蚂蚁集团g6初探