0

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?

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.