我只是一个学生,在vue.js中使用Laravel还是个新手。我在laravel-7中使用Laravel-mix版本6.0,在运行mix之后,我在public/js/app.js.console error description中得到这个错误(未捕获类型错误:无法设置未定义的属性'$Gate‘)。由于此原因,路由不工作,并且显示为禁用。
App.js中的错误行:
Vue.prototype.$gate = new _Gate__WEBPACK_IMPORTED_MODULE_2__.default(window.user);我的resource/assets/js/app.js文件包含以下代码:
import Gate from "./Gate";
Vue.prototype.$gate = new Gate(window.user);
在此文件上应用了laravel mix webpack。
我的gates文件包含以下代码:
export default class Gate{
constructor(user){
this.user = user;
}
isAdmin(){
return this.user.type === 'admin';
}
isUser(){
return this.user.type === 'user';
}
isAdminOrAuthor(){
if(this.user.type === 'admin' || this.user.type === 'author'){
return true;
}
}
isAuthorOrUser(){
if(this.user.type === 'user' || this.user.type === 'author'){
return true;
}
}
}
任何帮助都将不胜感激。谢谢。
发布于 2021-05-04 14:37:04
试试这个:
import Gate from "./Gate";
const $gate = new Gate(window.user);
Vue.prototype.$gate = $gate;
https://stackoverflow.com/questions/67166414
复制相似问题