[Vuejs]-How to import class (.js file) in a .vue file?

1👍

 export default class Authenticator {
    // ...
 }

And import in file:

  import Authenticator from "path/to/file/authenticator.js
  var Auth = new Authenticator ();

0👍

Pretty hard to help without your code, but here’s a basic example:

Authenticator.js

'use strict';

class Authenticator {
    // ...
};

module.exports.Authenticator = Authenticator;

Login.vue

<script>
import Authenticator from 'path/to/Authenticator.js';

const AuthenticatorInstance = new Authenticator;

// use it...

</script>

0👍

Authenticator.js

class Authenticator {
    //
    };

export default new Authenticator;

Login.vue

<script>
import Authenticator from 'path/Authenticator';
</script>

Leave a comment