我在将2个条目包含到index.html(包括BaseAjax.ts,Admin.ts和Test.ts的输出)中时遇到问题,Admin.ts和Test.ts在BaseAjax.ts中导入了相同的类'BaseAjax',但是当我检查Chrome调试,将BaseAjax分为2个变量差异。我该如何设置webpack或打字稿代码以使一个静态类BaseAjax像C#。
我试图使用webpack.ProvidePlugin插件使BaseAjax成为要使用的全局类,但它不在窗口属性中。
BaseAjax.ts
export class BaseAjax {static AjaxProcess: number = 0;}
Admin.ts
import {BaseAjax} from "./BaseAjax";
$(document).ready(()=>{BaseAjax.AjaxProcess++;})
window["ajax1"] = BaseAjax;`
Test.ts
import {BaseAjax} from "./BaseAjax";
$(document).ready(()=>{BaseAjax.AjaxProcess++;});
window["ajax2"] = BaseAjax;`
index.html
< script type="text/javascript" src="/dist/BaseAjax.js"></ script>
< script type="text/javascript" src="/dist/Form.js"></ script>
< script type="text/javascript" src="/dist/Test.js"></ script>
准备好文档后在Chrome控制台上检查时,BaseAjax.AjaxProcess = 1
(应为2)和window["ajax1"] != window["ajax2"]
(应为相等)。