0

I have a form.js stored in my resource/js/

class Form{
    constructor(){
        //more coding here
    }

    //more coding here
}

My question is how can I import the file above inside my .vue file? I tried these below:

<template>
    //some html here
</template>

<script src="../form.js"></script>
<script>

    export default{
        data(){
            return {
                form: new Form({
                    title: '',
                    body: ''
                })
            }
        }
    }
</script>

But still getting these error:

[Vue warn]: Error in data(): "ReferenceError: Form is not defined"


PROBLEM SOLVED:

export default class Form{
   //more coding here
}

import Form from '../form.js';

10
  • @Antonio already there from that link but does not work. I tried these import Form from '../form.js'; from that link but returns me an error [Vue warn]: Error in data(): "TypeError: form_js_WEBPACK_IMPORTED_MODULE_0___default.a is not a constructor" Commented Nov 19, 2019 at 21:45
  • Did you add export default in form.js? export default class Form { ... } Commented Nov 19, 2019 at 21:50
  • 1
    @Antonio already solved, thank you sir! already solved. I forgot I put it in the error class instead of form class. I'm so noob sorry. Commented Nov 19, 2019 at 22:05
  • 1
    Ah, are there another class Errors? Commented Nov 19, 2019 at 22:05
  • 1
    @Antonio yes Sir. I forgot I put the export to my Errors class instead of Form class. Glad it works now. thanks again. Commented Nov 19, 2019 at 22:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.