鍍金池/ 問答/HTML/ vue的單組件文件如何引入CDN文件?template里面不給加,這個cdn只有

vue的單組件文件如何引入CDN文件?template里面不給加,這個cdn只有在某個頁面才有用。

vue文件的 template 下不能放置 script。我有一個頁面需要用到一個cdn文件,其他頁面都不需要。我只想到用js添加,請問有什么好的解決方案嗎?

回答
編輯回答
扯不斷

1.有個問題,template里為什么不讓加
2.如果template確實不讓加,那就在你組件的mounted里用js加

var oHead = document.getElementsByTagName('HEAD').item(0); 
var oScript= document.createElement("script"); 
oScript.type = "text/javascript"; 
oScript.src="test.js"; 
oHead.appendChild( oScript); 
2018年6月3日 21:00