>[info] 有时需要异步加载 js 或者 css 文件,特别是异步加载 js 文件,如果过早执行 js 代码,就会报错,所以这里特意提供了动态加载 js 或 css 文件,加载文件后再执行 js 脚本,这样就安全了
##方法
`load_file(src, callback, type)`
##参数
| 参数名称 | 类型 | 使用说明 |
| --- | --- | --- |
| src | string | 需加载文件的地址 |
| callback | function | 可选,加载后的回调函数 |
| src | enum | 可选,script 或 style ,默认为 script |
##使用示例
```
// 动态加载 js 文件,加载完成后执行 js
load_file('__LIB__/qrcode/qrcode.min.js', function () {
var url = '{:\think\Request::instance()->url(true)}';
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: url,
width: 128,
height: 128,
colorDark : "#000000",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
})
// 动态加载 css 文件
load_file('__LIB__/foo/bar.css', undefined, 'style')
```