I'm struggling to get working the reactivity in vue.js inside the loop. Loop is rendering without any issue, But, when trying to fire an event it updates the content but not visible or render data in the page.
I've used the latest version of vue.js with bootstrap and jquery. I've tried adding key in the loop item but not working. But, when to update any other content by using v-model then it works.
Markup
<div id="app">
<div class="props">
<div class="prop-item" v-for="prop in modules.variations.properties">
<p>=== <strong v-text="prop.name"></strong> ===</p>
<ul>
<li v-for="value in prop.values" @click="activeProp(prop,value)">
<span v-text="value.name"></span>
</li>
</ul>
</div>
</div>
<input type="text" v-model="message">
<pre>{{ actives }}</pre>
<pre>{{ message }}</pre>
</div>
<script>
window.spdata = {
"variations":{
"properties":[
{
"id":1,
"name":"Color",
"values":[
{
"id":1,
"name":"Black",
},
{
"id":2,
"name":"Red",
},
{
"id":3,
"name":"Blue",
}
]
},
{
"id":2,
"name":"Size",
"values":[
{
"id":4,
"name":"XL",
},
{
"id":5,
"name":"XXL",
},
{
"id":6,
"name":"XXXL",
},
]
},
{
"id":3,
"name": "Type",
"values":[
{
"id":8,
"name":"Premium",
},
{
"id":9,
"name":"Standard",
},
{
"id":10,
"name":"Luxary",
}
]
}
]
}
};
</script>
Javascript
new Vue({
el: "#app",
data: {
modules: window.spdata,
actives: {},
message: '',
},
created() {
this.modules.variations.properties.forEach((prop) => {
this.actives[prop.id] = null
});
},
methods: {
activeProp(prop, val) {
if (this.actives[prop.id] === val.id) {
this.actives[prop.id] = null;
} else {
this.actives[prop.id] = val.id;
}
}
}
})
this.actives. Change detection caveatsVue.$set()but forget to use in the created section and that is the issue. Thank you for notice.