Categories
Vue Answers

How to import functions from different JavaScript file in a Vue Webpack project?

Spread the love

Sometimes, we want to import functions from different JavaScript file in a Vue Webpack project.

In this article, we’ll look at how to import functions from different JavaScript file in a Vue Webpack project.

How to import functions from different JavaScript file in a Vue Webpack project?

To import functions from different JavaScript file in a Vue Webpack project, we use import.

For instance, we write

<script>
import test from "@/mylib";

console.log(test.foo());
//...
</script>

to import the mylib module’s default export as test.

Then we call the test.foo method.

@ is the alias for the src folder in the Vue project.

Conclusion

To import functions from different JavaScript file in a Vue Webpack project, we use import.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *