我有一个VueJS项目,我用vue-cli webpack启动它。我有一个javascript库,其中包含我在所有组件中需要的功能。我想知道我需要放置这个文件夹以及如何从Component1.vue中的JSLibrary1调用函数:
-myJSLibrary
JSLibrary1.js
JSLibrary2.js
JSLibrary1.js
var A = A || (function() {
class B {
function C(){
return “hello”;
}
}
var obj = new B();
return obj;
}());
项目结构
VueProject
build
config
src
assets
components
Component1.vue
App.vue
main.js
static
感谢。
答案 0 :(得分:4)
libraries.js
export const A = () => {
// your code
}
export const B = () => {
// your code
}
Component1.vue
<script>
import { A, B } from '~/path/to/libraries.js'
export default {
data () {
return {}
},
mounted () {
// execute A when components is rendered
A()
}
</script>