I have a question regarding Vuex. How can I properly set a value for signupError in my function signUp()?
I attempted using the following code snippets: commit(signupError, null)
and
$state.commit(signupError, null)
, but I encountered an error stating "ReferenceError: signupError is not defined".
Could you provide guidance on how to correctly set up signupError in the given scenario?
store.js
import Vuex from "vuex";
import Vue from "vue";
import { Auth } from "aws-amplify";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
user: null,
signupError: null
},
actions: {
async signUp({ commit }, { username, password, firstName, lastName }) {
commit(signupError, null)
try {
const data = await Auth.signUp({
username,
password,
attributes: {
email: username
}
});
} catch (error) {
state.signupError = err.message || err
console.log('error signing up:', error);
return error;
}
main.js
....
/* eslint-disable no-new */
new Vue({
el: '#app',
store: store, // Vuex mechanism to "inject" the store into all child components from the root component.
render: h => h(App),
router
})
reg.vue
....
await this.$store.dispatch('signUp', {....