[英]Django: Include a template containing a script tag into another script tag
[英]In static template, script tag to import another file not working
我已經創建了Field.js
和index.js
。 index.js
使用Field。 但是, Field.js
從未加載。 我的沙箱在下面。
是否無法在codesandbox中執行<script src="Field.js"></script>
? 它僅適用於src="index.js"
嗎?
這是我的沙箱-https: //codesandbox.io/s/l55933j36z
這是我們如何監聽自定義事件的示例。 這將允許您“等待”腳本並正確運行。
// This lives in you scrip dependancy. const scriptReadyEvent = new CustomEvent('MyScriptLoaded', { bubbles: true }); // Dummy a delay in loading a script function demoDelay() { return new Promise((resolve, reject) => { setTimeout(() => { resolve('foo'); }, 2000); }); } // Listen for script loaded document.addEventListener('MyScriptLoaded', () => { console.log('Script is loaded'); }); // The script would do this. demoDelay().then(() => { document.dispatchEvent(scriptReadyEvent); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.