In my Vue application, I have an array of stocks:
stocks : [
{'name' : 'Tesla', 'price' : 800},
{'name' : 'Microsoft', 'price' : 300},
]
I also have a conditional element that looks like this:
<template v-for="stock in stocks">
<div>{{ stock.name }}</div>
<div v-if="stock.hasOwnProperty('test')">test</div>
</template>
I have a method that sets the test property for a stock. For example:
this.stocks[0].test = true;
If, under this statement, I console.log(this.stocks)
I see the test
property for the first stock
. But, in the template, the element that is supposed to show up when a stock
has this property still doesn't show up. Why is this and how can I achieve showing/hiding stock elements dynamically based on whether they have the test
property?