在vue.js,vuex中获取406错误错误

问题描述

我正在一个项目上,在浏览器中收到406(不可接受)错误。我正在使用vuejs,vuex框架。 verify.vue代码:

<template>
  <div>
    <usernav/>
    <div class="container">
    <h1 style="padding:90px;"> Enter OTP</h1>
    <div>
      <mdb-input label="OTP" v-model="value" />
      <br />
      <mdb-btn color="info" @click="verify()">Verify</mdb-btn>
    </div>
    </div>
  </div>
</template>

<script>
import { mdbInput,mdbBtn } from 'mdbvue'
import usernav from './user_nav'
export default {
  name: 'otp',components: {
    mdbInput,mdbBtn,usernav
  },data () {
    return {
      value: ''
    }
  },methods: {
    verify () {
      this.$store.dispatch('VERIFY',{
        otp: this.value
      }).then(success => {
        console.log('success')
      }).catch(error => {
        console.log(error)
      })
    }
  }
}
</script>

<style scoped>
.container {
  width: 500px;
}
</style>

verify.js代码:

import { isAuthenticated } from './auth'
import axios from 'axios'

export default ({
  state: {
  },mutations: {
  },actions: {
    VERIFY: (payload) => {
      return new Promise((resolve,reject) => {
        const userId = isAuthenticated().user._id
        const token = isAuthenticated().token
        console.log(userId)
        console.log(token)
        axios
          .post(`https://onu-backend.herokuapp.com/api/onu/user/${userId}/verifyEmail`,payload,{
            headers: {
              Authorization: 'Bearer ' + token
            }
          }).then(response => {
            if (response.status === 200) {
              console.log(response)
              resolve(true)
            }
          }).catch(error => {
            reject(error)
          })
      })
    }
  }
})

isAuthenticated代码:

export const isAuthenticated = () => {
  if (localStorage.getItem('auth')) {
    return JSON.parse(localStorage.getItem('auth'))
  }
  return false
}

我得到的错误是:error image

谁能告诉我为什么会出现此错误?该代码中使用的api与邮递员进行了交叉检查,并且工作正常。我认为发送承载令牌有一些问题。请帮忙。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...