【发布时间】:2021-07-13 21:51:59
【问题描述】:
我只是一名学生,并且是使用 Laravel 和 vue.js 的新手。我在 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);
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;
}
}
}
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: php laravel vue.js laravel-7 laravel-mix