我正在尝试使用Laravel5.5和Vue.js2开发应用程序。我收到了以下错误
我认为vue.js无法向Laravel发送身份验证令牌。我正在尝试从vue.js发送身份验证令牌,如下所示
Vue.http.headers.common['Authorization'] = 'Bearer ' + Vue.auth.getToken()
我将此代码放在main.js
文件中。我在vue.js中有一个名为Auth.js
的包。但它没有用。
main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import VueResource from 'vue-resource'
import Auth from './packages/auth/Auth.js'
Vue.use(VueResource)
Vue.use(Auth)
Vue.http.headers.common['Authorization'] = 'Bearer ' + Vue.auth.getToken()
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
if(to.matched.some(record => record.meta.forVisitors)) {
if(Vue.auth.isAuthenticated()) {
next({
path: '/dashboard'
})
} else {next()}
}
else if(to.matched.some(record => record.meta.Authenti)) {
if(!Vue.auth.isAuthenticated()) {
next({
path: '/'
})
} else {next()}
} else {next()}
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})