I have an array which i am looping over and outputting the text. I am trying to create an onClick method through which whatever text i click on, it gets pushed to a new array in whatever order they are clicked.
Here is my sample codepen
Here is my code setup:-
<div id="app">
<v-app>
<div v-for= "(item,index) in items" :key="item">
<span class="title" @click="onSelect">{{item.text}}</span>
</div>
</v-app>
</div>
and this is the script:-
new Vue({
el: '#app',
data() {
return {
items: [
{ text: 'foo', value: 'bar' },
{ text: 'bar', value: 'biz' },
{ text: 'buzz', value: 'buzz'}
]
}
},
methods: {
onSelect() {
let arr = []
console.log(arr)
}
}
})
Any help will be appreciated. Thank you.