如何解决在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 举报,一经查实,本站将立刻删除。