美文网首页
vue-cli-3中使用第三方js

vue-cli-3中使用第三方js

作者: ChasenGao | 来源:发表于2018-12-15 22:33 被阅读337次

通过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>

相关文章

网友评论

      本文标题:vue-cli-3中使用第三方js

      本文链接:https://www.haomeiwen.com/subject/ntezhqtx.html