验证中...
10月20日,北京【人工智能】源创会火热报名中,点击报名收获 AI 训练指南
vue instance中的computed的setter
原始数据 复制代码
<div id="app">
<!-- no setter error below -->
<textarea v-model="findNum"></textarea>
<!-- a working one -->
<textarea v-model="findObj.key2"></textarea>
</div>
<script>
new Vue({
name: 'num',
el: '#app',
data: {
numbers: [5, 8, 3],
arr: [
{ id: 1,
key1: "aaa",
key2: "bbb"
},
{ id: 2,
key1: "ccc",
key2: "ddd"
},
{ id: 3,
key1: "eee",
key2: "fff"
},
{ id: 4,
key1: "ggg",
key2: "hhh"
},
],
},
// result cached
computed: {
findNum() {
return this.numbers.find(num => num === 8);
},
findObj() {
return this.arr.find(member => member.key1 === "eee");
}
},
});
</script>

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助