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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.