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); }, }
使用 createElement
方法:app
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> 在頁面中調用
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>