programing

vuex 알 수 없는 작업 유형: 'auth/Signup'

sourcetip 2022. 7. 15. 23:28
반응형

vuex 알 수 없는 작업 유형: 'auth/Signup'

vuex에서 인증 모듈을 사용하여 등록 페이지를 생성하려고 했습니다.모듈에 액션에서 가입하기 위한 api를 올렸습니다.이 코드를 사용해 보니 콘솔에 "vuex" 알 수 없는 액션타입: auth/signUp"이라고 표시되어 있었습니다.제가 잘못한 게 있습니까?이거 풀 수 있는 사람?

이것은 vuex 인증 모듈입니다.

// store/auth/index.jx

import auth from '@/API/API_Auth'

const state = () => ({})
const getters=()=>({})
const mutations = () => ({})

const actions = () => ({
    signUp({commit},data){

        return auth.signUp(data)
            .then(res=>{
                console.log(res)
            })
            .catch(err=>{
                console.log(err)
            })
    }
})

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}

내 vuex 스토어

//   store/index.js

import Vue from "vue";
import Vuex from "vuex"
import auth from './module/auth'

Vue.use(Vuex);
export default new Vuex.Store({
    modules: {
        auth,
    },
    state:{},
    getters:{},
    mutations:{},
    actions:{},

})

스토어와 라우터를 main.js로 Import했습니다.

// main.js
import store from "./store"
import router from "./router";

new Vue({
  store,
  router,
  render: (h) => h(App),
}).$mount("#app");

이 컴포넌트는 액션을 호출하는 등록 컴포넌트입니다.

// src/component/signup.vue

<script>
export default {

  data() {
    return {
      name: "",
      telNumber: "",
    };
  },
  methods: {
    handleSubmit() {
          let name= this.name
          let telNumber= this.telNumber
        this.$store.dispatch("auth/signUp", {name,telNumber})
        .then(res=>{
          this.$router.push({path: 'otp'});
        })
        .catch(err=>{console.log(err)})
      }
    }
  }
};
</script>

Vuex 모듈이 잘못 설정됨actions,mutations,그리고.getters함수로 사용할 수 있습니다.오직.state함수여야 하고 나머지는 객체여야 합니다.

const state = () => ({}) // ✅ function
const getters = {} // ✅ object
const mutations = {} // ✅ object

const actions = { // ✅ object
    signUp({ commit }, data) {}
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
} 

언급URL : https://stackoverflow.com/questions/70950397/vuex-unknown-action-type-auth-signup

반응형