'import js file from public folder in a vue component (Laravel)
I need to import a file "js" from folder "public" in a vue component.
my Vue component:
<template>
<div>
<h2>Hello</h2>
</div>
</template>
<script>
import {myplugin} from "/public/vendor/jquery/jquery.min.js";
export default {
name: "pageone"
}
</script>
but i receive an error in compiling phase, can someone help me?
Solution 1:[1]
(Although it's not a very good idea to place your libraries/packages to public folder when using compilers), if you really want to place it in public folder, you should use a relative_path.
import {myplugin} from "../../public/vendor/jquery/jquery.min.js";
However, I'd install it as npm package and leverage laravel-mix for adding jquery in my build.
Solution 2:[2]
No need to import it.
Just add a <script src="/path/to/your.js"> into head section of public/index.html.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | senty |
| Solution 2 | ZhangChn |
