VueJs:导入自定义js库

use*_*831 2 javascript libraries vue.js

我有一个以vue-cli webpack开头的VueJS项目。我有一个具有所有组件所需功能的javascript库。我想知道我需要在哪里放置此文件夹,以及如何在Component1.vue中从JSLibrary1调用函数:

-myJSLibrary
    JSLibrary1.js
    JSLibrary2.js
Run Code Online (Sandbox Code Playgroud)

JSLibrary1.js

var A = A || (function() {
    class B {
        function C(){
            return “hello”;
        }   
    }       
    var obj = new B();
    return obj;
}());
Run Code Online (Sandbox Code Playgroud)

项目结构

VueProject
   build
   config
   src
    assets
    components
        Component1.vue
    App.vue
    main.js
   static
Run Code Online (Sandbox Code Playgroud)

谢谢。

tri*_*ibe 5

library.js

export const A = () => {
  // your code
}

export const B = () => {
  // your code
}
Run Code Online (Sandbox Code Playgroud)

Component1.vue

<script>
import { A, B } from '~/path/to/libraries.js'
export default {
  data () {
    return {}
  },
  mounted () {
    // execute A when components is rendered
    A()
  }    
</script>
Run Code Online (Sandbox Code Playgroud)