你好,@JellyBool laravel 5.5 版本 使用视频中的方式api_token 认证报错了
bootstrap.js
// let token = document.head.querySelector('meta[name="csrf-token"]');
// let api_token = document.head.querySelector('meta[name="api_token"]');
let token = $('meta[name="csrf-token"]').attr('content');
let api_token = $('meta[name="api_token"]').attr('content');
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');
}
if(api_token){
window.axios.defaults.headers.common['Authorization'] = api_token.content;
} else {
console.error('API-Token');
}
vue组件
methods: {
changeStatus(row){
let data = {
id:row.id,
status:row.bulletin_status
};
this.axios.post('/api/admin/change_status', data).then(response =>{
return response;
});
}
app.js
require('./bootstrap');
import axios from 'axios';
import VueAxios from 'vue-axios';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-default/index.css';
import DataTables from 'vue-data-tables';
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.use(ElementUI);
Vue.use(DataTables);
Vue.use(VueAxios, axios);
Vue.component('example', require('./components/Example.vue'));
Vue.component('TableSearch', require('./components/TableSearch.vue'));
const app = new Vue({
el: '#app'
});
api.php 路由
Route::middleware('auth:api')->post('/admin/change_status', function (Request $request) {
return $request;
});
不知道是什么原因