Anyone have an idea what my issue may be here?
I have two buttons changing a data value ( categoryName
). I know this is working as intended.
Then I'm trying to use conditional rendering to render the <template>
if business.category
is equal to categoryName
I know that conditional formatting works if I manually type in a new value for categoryName. But something isn't working with the buttons updating the value.
Here's the code
<div>
<button v-on:click="categoryFilter = 'cheap'">cheap</button>
<button v-on:click="categoryFilter = 'expensive'">expensive</button>
</div>
<template v-for="business in cardData" v-if="business.category == '{{ categoryFilter }}'">
<!-- HTML Content goes here -->
</template>
And the JSON
data: {
categoryFilter: "",
cardData: [
{
category: "expensive"
}
]
}
Issue resolved.
Instead of:
v-if="business.category == '{{ categoryFilter }}'"
I removed the curly brackets and single quotes:
v-if="business.category == categoryFilter"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.