In my application, i am working on storing user form responses. I have created pinia store and created each forms object. Using this store into my component and passing the getter function of that store into variable,
That variable, i am using as a v-model. After giving input also it is not returning anything. As well as i am not getting any error for this. Did i follow any wrong approach?
Userstore.js
import { defineStore } from 'pinia';
export const userResponses = {
formsResponses: {
form1: {
input1: '',
},
},
};
export default defineStore('userStore', {
state() { return userResponses; },
getters: {
getFormsInput: (state) => state.formsResponses.form1,
},
actions: {
setFormsResponses(formResponses) {
this.formsResponses.form1 = formResponses;
},
},
});
Form1.vue
<template>
<input type="text" name="input_form" v-model="input"/>
<button type="Primary" @click="submit">submit</button>
</template>
<script setup>
import { computed, ref } from 'vue';
import useUserStore from '@/store/userStore';
const userStore = useUserStore();
const input = ref('');
const responses = computed(() => userStore.getFormsInput);
reponses.value.input1 = input.value;
function submit() {
console.log(reponses.value.input1); // it is giving nothing
}
</script>
Why i am not able to use getters or not updating the value? Shall i directly can use getters into v-model?