遇到某个功能需要引用外部 js 文件,但是它又没有 npm 包,这时候如果我们可以这样处理,例如:
<script setup lang="ts">
let script = document.createElement("script");
script.setAttribute(
"src",
"//res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"
);
document.head.appendChild(script);
script.onload = () => {
const wxlogin = new WxLogin({
//
});
};
</script>
参考: https://stackoverflow.com/questions/45047126/how-to-add-external-js-scripts-to-vuejs-components