【问题标题】:Refer to the undefined value in Checking ID overlap method参考检查ID重叠方法中的未定义值
【发布时间】:2021-11-17 07:54:47
【问题描述】:

在下面的代码中,我正在检查 Id 重叠。

我想将设置到 v-model 的值作为有效负载移交

我用的是mapState,所以交了this.info.userid,但是不行。

它一直说我指的是未定义的值。

我应该参考什么值?

这是我的注册.vue

<div class="user-details">
  <div class="input-box">
    <span class="details">아이디</span>
    <div class="validate-box">
      <Field
        :rules="validateId"
        type="text"
        placeholder="아이디를 입력하세요"
        v-model="info.userId"
        name="userId"
        required />
      <ErrorMessage
        class="error-box"
        name="userId" />
    </div>
    <div>
      <button @click="idCheck">
        중복확인
      </button>
    </div>
 </div>
</div>

import { mapState } from 'vuex'
import { Field, Form, ErrorMessage } from 'vee-validate';
methods: {
    async idCheck() {
      this.$store.dispatch('signup/idChecking', {
        userId: this.info.userId
      })
    }
  },
  computed: {
    ...mapState('signup',{
      info: 'Userinfo'
    })
  }

下面的代码是我的商店registration.js

 state: {
    Userinfo: {
      userId: '',
      password: '',
      passwordConfirm: '',
      userName: '',
      birthDate: '',
      phoneNumber: '',
      email: '',
      year: '',
      month: '',
      day: ''
   }
},
actions: {
    async idChecking(payload) {
      const { userId } = payload
      axios.get(`http://??.???.???.???:????/api/check/${userId}`)
      .then(res => {
        console.log(res)
      })
      .catch(error => {
        console.log(error)
      })
    }
}

【问题讨论】:

    标签: vue.js axios vuex


    【解决方案1】:

    我解决了这个问题。 我没有将“状态”放在异步 idChecking 方法中。 async idChecking(state, payload)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      相关资源
      最近更新 更多