Laravel:Vue未针对插件定义

发布于 2025-02-07 17:41:46 字数 710 浏览 1 评论 0原文

我正在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

虚拟世界 2025-02-14 17:41:46

使用window.vue = require('vue')在窗口上初始化vue。默认值;
您的app.js应该看起来像

window.Vue = require('vue').default;
import Vue from 'vue';
require('./plugin.js');

Initialize vue on window using window.Vue = require('vue').default;
Your app.js should look like

window.Vue = require('vue').default;
import Vue from 'vue';
require('./plugin.js');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文