How to deselect an item from a list of products when selecting another? Only one can be marked at a time #8239
Answered
by
ChrisGV04
faridsa
asked this question in
Help/Questions
-
Beta Was this translation helpful? Give feedback.
Answered by
ChrisGV04
May 6, 2023
Replies: 1 comment 4 replies
-
Hi @faridsa! As with almost any problem, there might be several ways to solve it. I believe that a simple way to achieve it is by using the currently selected state that you have inside of your <script setup>
import { computed } from 'vue';
import { useOrderStore } from '../stores/customOrder.js';
const data = useOrderStore();
// ... All of your logic
// This is no longer needed. Use the isSelected computed property instead
// ❌ const status = reactive({ isSelected: false });
// Computed property that checks if itself is the selected fabric by comparing it to the
// selected fabric from the pinia store
const isSelected = computed(() => data.fabric && data.fabric.id === props.id);
function addToOrder(item) {
// This is no longer needed 👇
if (counter.count >= 1) {
status.isSelected = true;
}
// 👆
// ... The rest of the logic
}
</script>
<template>
<article class="flex flex-col justify-center p-2 mx-auto" :id="id">
<div class="relative mb-4 overflow-hidden image w-68 h-75 rounded-3xl">
<!-- ... -->
<!-- Replace the status.isSelected for the computed isSelected property -->
<div id="selection" class="rounded-3xl" :class="{ selected: isSelected }">
<!-- ... -->
</div>
</div>
<!-- ... -->
</article>
</template> If you have any questions or need help with that methodology, I'm glad to help. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
faridsa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @faridsa!
As with almost any problem, there might be several ways to solve it. I believe that a simple way to achieve it is by using the currently selected state that you have inside of your
customOrder.js
pinia store inside of theFabricModule
component with a computed property that checks if itself is the selected fabric.