In the use of vue.js, on the definition of attribute id number how to get it? I want to $refs read id="20"
value. I hope console.log is 21,10,15
. go to the jsfiddle
Look at:
var app = new Vue({
el: "#app",
data: {
fruit: [{
id: 21,
name: 'Peach'
}, {
id: 10,
name: 'Apple'
}, {
id: 15,
name: 'Lemon'
}],
branid: ''
},
mounted() {
console.log(this.$refs)
}
})
<div id="app">
<ul>
<li v-for="item in fruit" :id="item.id" ref="branid">{{item.name}}</li>
</ul>
</div>
you don't need to get it through this.$refs, it is in your fruit array so you can easily get it by using map or filter function:
Example:
mounted() {
var ids = this.fruit.map(function(obj) {
return obj.id;
});
console.log(ids)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.