How to import js file in the Vue component?

devquora
devquora

Posted On: Nov 08, 2022

 

    1 Answer Written

  •  devquora
    Answered by devquora

    To import a JavaScript file in a Vue component, you can use the import statement at the top of your component's script section.

    Assuming you have a JavaScript file named example.js located in the same directory as your Vue component, you can import it like this:

    import Example from './example.js';
    
    export default {
      // Component code here
    }
    
    

    In the example above, we're importing the Example object from the example.js file. The path to the file is relative to the current component's directory, hence the ./ before the file name.

Related Questions

Please Login or Register to leave a response.

Related Questions

Vue.js Interview Questions

What is Vue.js?

Vue js is progressive javascript script used to create dynamic user interfaces.Vue js is very easy to learn.In order to..

Vue.js Interview Questions

List some features of Vue.js.

Vue js comes with following features Templates Reactivity Components Transitions Routing ..

Vue.js Interview Questions

Explain Life cycle of Vue Instance.

The Life cycle of each Vue instance goes through a series of initialization steps when it is created. – for example, ..