I have a button with initial value is true (Checked), then I switch it to false (Unchecked) and submit the form. After the form was submitted I set the button back to true by committing a Vuex mutation (called resetOrder). Even the value is true, but the button is still unchecked.
Here is my code:
<template>
<div class="flex border-b border-40 remove-bottom-border">
<div class="w-1/5 px-8 py-6">
<label for="do_ship" class="inline-block text-80 pt-2 leading-tight">
Giao hàng ngay
</label>
</div>
<div class="py-6 px-8 w-1/2">
<toggle-button id="do_ship" v-model="do_ship"
:labels="{checked: 'Yes', unchecked: 'No'}"
:width="60"
:height="26"/>
</div>
</div>
</template>
<script>
import {ToggleButton} from 'vue-js-toggle-button'
export default {
name: "DoShip",
computed: {
do_ship: {
get() {
console.log(this.$store.state.order.order.do_ship); // It shows the value is true, but the button is still unchecked.
return this.$store.state.order.order.do_ship;
},
set(value) {
this.$store.commit('order/setOrder', {
attribute: 'do_ship',
value: value
})
}
}
},
components: {
ToggleButton
}
}
</script>
<style scoped>
</style>
I have a button with initial value is
true
(Checked), then I switch it tofalse
(Unchecked) and submit the form. After the form was submitted I set the button back totrue
by committing a Vuex mutation (calledresetOrder
). Even the value is true, but the button is still unchecked.Here is my code:
My submit function:
My mutation