当前位置:网站首页>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>
边栏推荐
- 2020-9-23 use of QT timer qtimer class.
- Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
- 实现strStr() II
- Redis——大Key问题
- Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
- Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
- Eggjs -typeorm treeenity practice
- Latex error: the font size command \normalsize is not defined problem solved
- 查询GPU时无进程运行,但是显存却被占用了
- Pytest (2) mark function
猜你喜欢
查询GPU时无进程运行,但是显存却被占用了
unittest.TextTestRunner不生成txt测试报告
一口气说出 6 种实现延时消息的方案
web自动中利用win32上传附件
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Detailed definition of tensorrt data format
There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)
IDEA公布全新默认UI,太清爽了(内含申请链接)
Sublime Text 配置php编译环境
ctf三计
随机推荐
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
Eggjs -typeorm 之 TreeEntity 实战
Distributed transactions: the final consistency scheme of reliable messages
提高用户体验 防御性编程
The intern left a big hole when he ran away and made two online problems, which made me miserable
Selenium+msedgedriver+edge browser installation driver pit
Learn about various joins in SQL and their differences
记录一次RDS故障排除--RDS容量徒增
实现strStr() II
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
奇葩pip install
ctf-web之练习赛
JS modification element attribute flipping commonly used in selenium's Web Automation
pytest(1) 用例收集规则
(the 100th blog) written at the end of the second year of doctor's degree -20200818
selenium的web自动化中常用的js-修改元素属性翻页
web自动化切换窗口时报错“list“ object is not callable
2020-9-23 use of QT timer qtimer class.
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
Win10: add or delete boot items, and add user-defined boot files to boot items