I have a Vue component that modifies a Pinia state and is reactive to the state being updated. This component is something similar to:
<script setup>
import { useStore } from '@/stores/myStore/';
import { reactive } from 'vue';
// Getting the store and using reactive form for the dropdown
const myStore = useStore();
const entryForm = reactive({storeBool: myStore.theBool});
// Function to mutate the state
const onChange = () => {
myStore.theBool= (entryForm.storeBool=== 'true')
}
</script>
<template>
<select v-model="entryForm.storeBool" @change="onChange()">
<option value=false>Option 1</option>
<option value=true>Option 2</option>
</select>
</template>
This component is working fine, where selecting a new dropdown value will mutate the state. I have another component that is importing the same store and uses a function in a button to myStore.$reset()
. I can see the state value is being changed, but the dropdown is not reacting to the state change. How can I have the dropdown show the reset state?
This reset button component:
<script setup>
import { useStore } from '@/stores/myStore/';
const myStore = useStore();
const resetClick = () =>{
myStore.$reset();
}
</script>
<template>
<button @click="resetClick()"></button>
</template>