1、直接在dom上操作:
export default {
mounted() {
const s = document.createElement('script');
s.type = 'text/javascript';
s.src = 'https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js';
document.body.appendChild(s);
},
}
2、用Vue 的 createElement
方法:
export default {
components: {
'dingtalk': {
render(createElement) {
return createElement(
'script',
{
attrs: {
type: 'text/javascript',
src: 'https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js',
},
},
);
},
},
},
}
// 使用 <dingtalk></dingtalk> 在页面中调用
3、通过封装一个组件 remote-js
实现:
export default {
components: {
'remote-js': {
render(createElement) {
return createElement('script', { attrs: { type: 'text/javascript', src: this.src }});
},
props: {
src: { type: String, required: true },
},
},
},
}
使用方法:
<remote-js src="https://g.alicdn.com/dingding/dinglogin/0.0.2/ddLogin.js">
</remote-js>
参考:
http://www.jb51.net/article/111634.htm
http://blog.csdn.net/sinat_17775997/article/details/55798611
原文链接:https://www.cnblogs.com/wang715100018066/p/7690641.html