在实际开发中会遇到需要引入外部JS的情况,使用在index.html里直接引入是可以的,但是无疑不是最好的选择,经过查阅各种资料,最后经过实际实验采用以下办法解决:
1、在vue文件里引入
<template>
<div id="indentify-code">
<remote-js cdn="https://g.alicdn.com/sd/ncpc/nc.js?t=2015052012"></remote-js>
</div>
<div id="indentify"></div>
</template>
2、js部分
......
components: {
'remote-js': {
render() {
return h('script', {
//attrs: {
type: 'text/javascript',
src: this.cdn
//}
})
},
props: {
cdn: {
type: String,
required: true
}
}
}
}
......