I have a huge list of data in a Vue component that I would like to dynamically populate. I'm trying to do that by a loop, and a global variable. It looks like below:
var filterItems = document.querySelectorAll('.filter-title');
var filterItemsTitle = filterItems.innerHTML;
var arr = [];
function buildContent() {
for (var i = 0; i < filterItems.length; i++) {
arr.push(filterItems[i].innerHTML);
}
console.log(arr)
}
window.onload = buildContent
var titleFilter = new Vue({
// in items its refering to arr built in buildContent
el: '#filter',
data: {
// arr comes from buildContent() - I think...does this work?
items: arr,
filters: [
{ label: 'All Titles', value: false },
{ label: 'a', value: 'a' },
{ label: 'b', value: 'b' },
{ label: 'c', value: 'c' },
],
currentFilter: false,
},
methods: {
filterItems: function(e){
console.log(items)
}
}
});
Basically what I want to do is take the arr variable which is populated with an array of content in the buildContent() loop and reference it in the items data section of my vue component
- is this possible? Or no?
- How can I
console.log()theitemsobject? When I try to do it it is undefined