如何使用vue-js和laravel修复405(方法不允许)



嗨,开发人员我目前遇到的问题是,这个项目是开发人员创建的一个旧项目。现在,我们需要调整其中的一些功能。现在,我已经将文件提取到本地主机文件夹中,现在可以在run-watch和artisan serve上无错误地工作。所以这里的问题是在控制台上登录,它显示http://localhost:8000/project/oauth/token405(方法不允许(,我真的不明白为什么它会在本地主机上显示,但在实时服务器上它是工作的。

该项目使用VueJs和Laravel作为后端创建。我将向你们展示身份验证功能。

登录功能:

authenticate(){
this.login_alert = false
this.$validator.validateAll().then((result)=>{
if(result){
const self = this;

const authUser = {}
try{
const data = {
username: this.email,
password: this.password,
remember: this.remember_me,
client_id: '2',
client_secret: 'secret',
grant_type : 'password',
scope : ''
}
this.$store.dispatch('AUTH_REQUEST',data)
.then(response=>{
console.log(data);
authUser.access_token = response.access_token
authUser.refresh_token = response.refresh_token
authUser.expires_in = response.expires_in
window.localStorage.setItem('project_token',JSON.stringify(authUser))
/*LOGIN*/
this.login_alert = false
this.loading = false
window.location.reload()
})
.catch(error=>{
this.login_alert = true
window.localStorage.removeItem('project_token')
this.loading = false
})
}catch(err){
console.log(err);
}
}
})

}

对于AUTH REQUEST:

AUTH_REQUEST:({commit,dispatch},obj)=>{
return new Promise((resolve,reject) => {
axios({
url: '/project/oauth/token',
data: obj,
method:'post',
config:'JSON'
})
.then(response=>{
if(response.status == 200){
resolve(response.data);
}
})
.catch(error=>{
reject(error);
localStorage.removeItem('project_token');
commit('AUTH_ERROR',error);
})

})
},

希望有人能体验到这一点。谢谢

在我的情况下,应该正确指定路线的编译,例如

async purchaseDelete(purchase) {
Csrf.getCookie();
return Api.delete('/api/purchase_settings/${purchase.id}');
},

axios删除方法上的单个勾号不能正确表示

async purchaseDelete(purchase) {
Csrf.getCookie();
return Api.delete(`/api/purchase_settings/${purchase.id}`);
}

当更改为反勾号时,它会以正确的结果进行响应

最新更新