I want to show conditional buttons inside a v-for loop using v-if (only when category_id=1): this is the vuejs part:
<div class="w3-margin-bottom" v-for="category in categorys" v-bind:key="category.category_id">
<div class="w3-quarter w3-button">
<i class="w3-small" v-if="category.category_id='1'">
<button class="w3-button w3-green">Sauce Blanche</button>
<button class="w3-button w3-green">Sauce Rouge</button>
</i>
<div class="w3-container w3-red w3-padding-16">
<div class="w3-clear">{{ category.category_des }}</div>
</div>
</div>
</div>
and this is my javascript part:
import axios from "axios";
export default {
data() {
return {
categorys: [],
category_id: null,
category_des: "",
};
},
methods: {
getCategory: function () {
axios.get("http://127.0.0.1:8000/api/Category/").then((response) => {
this.categorys = response.data;
});
},
v-if="category.category_id === '1'v-if,=needs to be==or===. Always double check your equal signs, this is a really easy mistake to make!