通过export导出 => main.js中使用require引入 => Vue.prototype全局加载
实例如下:
var other = require('2.js') //如果被引入的js文件还引入了外部文件,可以用这个方法引入
var tools = {
setTime:function () {
console.log(1)
}
}
export {
tools
}
main.js中引入
var aa = require('1.js')
Vue.prototype.tools = aa.tools
View或组件中使用
<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'home',
components: {
HelloWorld
}, mounted() {
this.tools.setTime()
}
}
</script>
网友评论