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';

schutte
  • 1,949
  • 7
  • 25
  • 45
  • @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"** – schutte Nov 19 '19 at 21:45
  • Did you add `export default` in form.js? `export default class Form { ... }` – Diamond Nov 19 '19 at 21:50
  • @Antonio already added Sir. Heres new error in my console **[Vue warn]: Error in render: "TypeError: _vm.form.errors.has is not a function"** – schutte Nov 19 '19 at 21:51
  • @Antonio the `Form class` actually working when inline to my vue file. But this time I want to separate it for multiple usage. – schutte Nov 19 '19 at 21:53
  • Could you provide codepen? – Diamond Nov 19 '19 at 21:53
  • @Antonio okey wait sir – schutte Nov 19 '19 at 21:54
  • @Antonio https://codepen.io/escbooster12/project/editor/AVpbNz two files there Sir. I'm not really mastered using codepen. but there is two files there. – schutte Nov 19 '19 at 22:03
  • 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. – schutte Nov 19 '19 at 22:05
  • 1
    Ah, are there another class `Errors`? – Diamond Nov 19 '19 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. – schutte Nov 19 '19 at 22:08

0 Answers0