EN: Load a JavaScript file from the server and execute it.
ZH: 动态加载 JavaScript 文件。
Usage:
loadScript( 'http://example.com/static/js/plugin-2.1.1.min.js', { id: 'iamid', // (Optional) script ID, default none timeout: 5000, // (Optional) timeout, default `5000` isDefer: false, // (Optional) defer, default `false` } ) .then( res => { console.log(`Load JavaScript script: ${res}`); } ) .catch( err => { console.error(`Load JavaScript script: ${err.message}`) } ); Copy
loadScript( 'http://example.com/static/js/plugin-2.1.1.min.js', { id: 'iamid', // (Optional) script ID, default none timeout: 5000, // (Optional) timeout, default `5000` isDefer: false, // (Optional) defer, default `false` } ) .then( res => { console.log(`Load JavaScript script: ${res}`); } ) .catch( err => { console.error(`Load JavaScript script: ${err.message}`) } );
Output:
Load JavaScript script: loaded Copy
Load JavaScript script: loaded
JavaScript 资源路径
Optional
加载后回调函数
Rest
DOM ID
是否添加 defer 标签
超时时长
-- true 成功
EN: Load a JavaScript file from the server and execute it.
ZH: 动态加载 JavaScript 文件。
Usage:
Output: