1

I'm using laravel 5.3 and vuejs. I have defined a javascript class named 'Form' inside a js file named form.js and I want to create an object of this class in app.js file. I have added both js files in webpack and I have also required the 'form.js' file inside the app.js. But I get the following error :

Uncaught ReferenceError: Form is not defined ...

Here is my app.js code :

require('./bootstrap');
require('./form.js');

formElm = document.getElementById('form');

new Vue({
    el: "#form",
    data: {
        form: new Form(formElm)
    },
    methods: {
        ....
    }
});

And here is my form.js code :

class Form {
    constructor(formElm) {
        ...
    }
    ...
}

And this is how I've added the js files in gulpfile.js :

elixir(mix => {
    mix.sass('app.scss')
       .webpack(['app.js', 'form.js'], 'public/js/app.js');
});

Am I missing something ?

1 Answer 1

1

I guess you have to export it in order to use it. In your Form class: module.exports=Form or if you use the es6 import syntax export default Form

In your app js var Form = require('./form.js') should make it work

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.