用户流程如下:
我正在尝试使用
我认为它是Header部分...
我假设我向axios.post
发出请求时没有正确的标题数据。
VUE组件方法
saveCarDetails(){
let config = {
'Content-Type': 'application/json',
}
let currentObj = this;
axios.post('/api/car/store', {
user_id: currentObj.auth_user.id,
car: currentObj.car
}, config)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
currentObj = error;
})
.then(() => {
this.errors.clear();
})
}
Bootstrap.js
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
答案 0 :(得分:2)
我认为您需要在RouteServiceProvider中更改中间件以使用Web而不是api。