使用 qiankun 来进行子应用拆分的时候遇到了以下问题
因为子应用是一个原生的 html 项目,所以有很多挂载在 window 上的属性以及方法
其中有一个鼠标事件处理的问题
```js
propagateMouseEventToCanvas(event) {
if (!event.isSimulated) {
console.log(window ,'-------------------------------');
const eventType = event.type;
// Create and dispatch a simulated event to the canvas
const simulatedEvent = new MouseEvent(eventType, {
clientX: event.clientX,
clientY: event.clientY,
screenX: event.screenX,
screenY: event.screenY,
button: event.button,
buttons: event.buttons,
ctrlKey: event.ctrlKey,
shiftKey: event.shiftKey,
altKey: event.altKey,
metaKey: event.metaKey,
relatedTarget: event.relatedTarget,
bubbles: true,
cancelable: true,
view: window
});
simulatedEvent.isSimulated = true; // Custom property to mark the event as simulated
this._canvas.dispatchEvent(simulatedEvent);
}
}
btnsWrapper.addEventListener('mousemove', this.scene.propagateMouseEventToCanvas.bind(this.scene));
btnsWrapper.addEventListener('mousedown', this.scene.propagateMouseEventToCanvas.bind(this.scene));
btnsWrapper.addEventListener('mouseup', this.scene.propagateMouseEventToCanvas.bind(this.scene));
```
打印的时候发现 window 为一个 proxy Object
并且控制台报错了
```js
helpers.ts:122 Uncaught TypeError: Failed to construct 'MouseEvent': Failed to read the 'view' property from 'UIEventInit': Failed to confert value to 'Window'.
```
按 gpt 改成 globalThis 也无法解决,不是很理解报错的原因以及解决方案,有没有大佬赐教一下 |
|