vue引入第三方js 及css

vue引入第三方js第一时间我们会想到在index.html下使用script标签引入,通常情况下script是可以满足我们的需求

说的是通常会满足,作为写代码的我们,也有运气差的时候。写法、路劲都没有问题就是引入失败。这个时候我们就需要洗个头冷静下

换个头脑,这不document给我们提供一个很好用的方法document.write()

document.write() 用法

在JavaScript中document.write()函数可以向文档写入HTML表达式或JavaScript代码,用法“document.write(exp1,exp2,exp3,…)”,该函数可接受任何多个参数,并将其写入文档中。

document.write() 说明

虽然根据 DOM 标准,该方法只接受单个字符串作为参数。

我们通常按照两种的方式使用 write() 方法:一是在使用该方在文档中输出 HTML,另一种是在调用该方法的的窗口之外的窗口、框架中产生新文档。在第二种情况中,请务必使用 close() 方法来关闭文档。

document.write() 实例

<html>
<body>
// html <script type="text/javascript"> document.write("Hello World!"); </script> </body> </html>
引入js(绝对路径)
    <script>
        document.write('<script src="/js/config.js?v=' + Math.random() + '"><\/script>');
        document.write('<script src="/js/mapvgl.js?v=' + Math.random() + '"><\/script>');
    </script>
引入css
<link rel="stylesheet" href="">
必须要有rel="stylesheet" 

 

posted @ 2021-09-26 22:06  Jim-vue  阅读(1117)  评论(0编辑  收藏  举报