Vue.js 如何在nuxt/axios中设置baseUrl?
baseURL未在nuxt axios mudule中设置,我无法使用nxut/auth模块进行身份验证 这是nuxt.config.js:Vue.js 如何在nuxt/axios中设置baseUrl?,vue.js,authentication,axios,nuxt.js,Vue.js,Authentication,Axios,Nuxt.js,baseURL未在nuxt axios mudule中设置,我无法使用nxut/auth模块进行身份验证 这是nuxt.config.js: auth: { strategies: { local: { endpoints: { login: {url: 'auth/login', method: 'post', propertyName: 'data.access_token'},
auth: {
strategies: {
local: {
endpoints: {
login: {url: 'auth/login', method: 'post', propertyName: 'data.access_token'},
user: {url: 'user', method: 'get', propertyName: 'data'},
logout: {url: 'auth/logout', method: 'post'}
},
tokenRequired: true,
tokenType: 'Bearer',
},
redirect: {
home: '/',
login: '/login',
logout: '/logout'
}
}
},
axios: {
baseURL: "api.dvl/api/v1/"
},
一切都是对的,但如果我提出要求,它会要求
怎么了
我的登录页面:
data() {
return {
title: process.env.title.fa,
form: {
email: null,
password: null,
remember: false
}
}
},
methods: {
async login() {
await this.$axios.$post('/login', this.form)
this.$auth.login({ data: this.form })
}
}
您的异步登录错误。请尝试以下代码:
methods: {
async login() {
await this.$auth.loginWith('local', {
data: {
email: this.email,
password: this.password
}
})
this.checkLogin()
},
checkLogin() {
console.log(this.$auth.user)
}
}
您的异步登录错误。请尝试以下代码:
methods: {
async login() {
await this.$auth.loginWith('local', {
data: {
email: this.email,
password: this.password
}
})
this.checkLogin()
},
checkLogin() {
console.log(this.$auth.user)
}
}
请分享一些解释,以便其他人可以从您的答案中学习-到底是什么错误,以及您的代码如何工作不同?您已经使用了nuxt auth模块,并在nuxt config中设置了它的本地策略。因此,对于登录,您必须使用$auth.loginwith('local',data)。请分享一些解释,以便其他人可以从您的答案中了解-到底是什么错误,以及您的代码如何工作不同?您使用了nuxt auth模块,并在nuxt config中设置了它的本地策略。因此,对于登录,您必须使用$auth.loginwith('local',data)。