0👍
✅
Pass the ts value as parameter and use a method, see the code snippet below
var vm = new Vue({
el: '#example',
data : {
alertes:[
{text: "qeq2", ts: '0'},
{text: "qeq3", ts: '5'},
{text: "qeq3", ts: '15'}
]
},
methods: {
bgcoul: function (ts) {
console.log(ts);
return { };
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<div id="example">
<div v-for=" alerte in alertes" v-bind:class="bgcoul(alerte.ts)">
{{alerte.text}} {{alerte.ts}}
</div>
</div>
0👍
this.ts
don’t exist. this.alertes
is a array of objects where each object has ts
property.
computed: {
bgcoul: function () {
this.alertes.forEach(alert => console.log(alert.ts) )
return { };
}
}
Source:stackexchange.com