当前位置: 代码迷 >> 综合 >> vue-cli中 如何引入全局的js
  详细解决方案

vue-cli中 如何引入全局的js

热度:33   发布时间:2024-02-28 06:33:40.0

你需要这样 this.test.test_log 这样来调用
同时在VUE中 添加的全局方法最好是加上$标识符 这样好区分
完整过程
在 main.js中

import test from './assets/js/test.js'
Vue.prototype.$test = test
在组件中

methods:{

test:function(){this.$test.test_log()
}

}
test.js
然后export 的时候 改成这样
export default {
function test_log(){
console.log(123)
}
}

  相关解决方案