Laravel:Vue未针对插件定义
我正在尝试在laravel 8.4 / vuejs 2 < / code>中为全局函数创建一个插件。我尝试在与
app.js
plugin.js
app.js app.js
const Plugin = {
install(Vue, options) {
Vue.prototype.toTitleCase = (str) => {
return str.split(' ')
.map(w => w[0].toUpperCase() + w.substring(1).toLowerCase())
.join(' ');
}
},
}
Vue.use(Plugin)
app.js plugin.js >
import Vue from 'vue';
require('./plugin.js');
但是,我一直遇到错误:
Uncaught ReferenceError: Vue is not defined
at Object../resources/js/plugin.js
我尝试执行导入INT插件文件。但是,这只是导致更多错误。 我在做什么错?
I am trying to create a plugin for global functions in Laravel 8.4 / VueJs 2
. I have tried creating a file plugin.js
in the same folder as app.js
plugin.js
const Plugin = {
install(Vue, options) {
Vue.prototype.toTitleCase = (str) => {
return str.split(' ')
.map(w => w[0].toUpperCase() + w.substring(1).toLowerCase())
.join(' ');
}
},
}
Vue.use(Plugin)
app.js
import Vue from 'vue';
require('./plugin.js');
However I keep getting the error:
Uncaught ReferenceError: Vue is not defined
at Object../resources/js/plugin.js
I have tried doing the import int the plugin file. However this just leads to more errors.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用window.vue = require('vue')在窗口上初始化vue。默认值;
您的app.js应该看起来像
Initialize vue on window using window.Vue = require('vue').default;
Your app.js should look like