A form is used to submit text and two options which tell vue which column to display the text in. When the col2 radio button is checked the submitted text should display in
Your second check is !item.col==='two'
and would only display if it does not equal 'two'.
EDIT: The ! not operator is likely binding more closely than === so that will always return false. Add brackets to control the order of application. I say likely because it may be a bit of Vue magic that I'm not familar with, rather than a pure JavaScript expression.
I think you want to remove that exclamation mark. Or to make it !(item.col==='one')
to display for any value other than 'one'.
If for some reason, filtering the list is not an option, you can convert the element with both v-for
and v-if
in to a component and move the v-if
in to the component.
Original Example
Original Loop
<li v-for="item in info" v-if="item.col==='one'">
text: {{ item.text }}, col: {{ item.col }}
</li>
Suggested Refactor
Refactored Loop
<custom-li v-for="item in info" :visible="item.col==='one'">
text: {{ item.text }}, col: {{ item.col }}
</custom-li>
New Component
Vue.component('custom-li', {
props: ['visible'],
template: '<li v-if="visible"><slot/></li>'
})
Why don't use the power of Computed Properties ?
computed: {
infoOne: function () {
return this.info.filter(i => i.col === 'one')
},
infoTwo: function () {
return this.info.filter(i => i.col === 'two')
}
}
Then on each list just iterate over its respective property without the need to check. Example
<ol>
<li v-for="item in infoOne">{{item}}</li>
</ol>
Here the working fiddle
<div v-for="item in items">
<div v-if="checkThis(item.computeThisProperty)" />
<div v-else />
</div>
methods: {
checkThis(i) {
return this[i];
}
},
computed: {
myComputedProperty() {
return this.$store.state.something ? true : false;
}
}
<div class="row">
<div class="col-md-6">
<ol>
<li v-for="item in info">
<template v-if="item.col==='one'">
text: {{ item.text }}, col: {{ item.col }}
<template>
</li>
</ol>
</div>
<div class="col-md-6">
<ol>
<li v-for="item in info">
<template v-if="!item.col==='two'">
text: {{ item.text }}, col: {{ item.col }}
<template>
</li>
</ol>
</div>
</div>
Remove !
from second if v-if="item.col==='two'"
better you can do this way (to iterate only once):
<div class="row" v-for="item in info">
<div class="col-md-6">
<ol>
<li v-if="item.col==='one'">
text: {{ item.text }}, col: {{ item.col }}
</li>
</ol>
</div>
<div class="col-md-6">
<ol>
<li v-if="item.col==='two'">
text: {{ item.text }}, col: {{ item.col }}
</li>
</ol>
</div>
</div>