跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 第一次用 qiankun, 子应用 window 使用问题请教

发表于

使用 qiankun 来进行子应用拆分的时候遇到了以下问题 因为子应用是一个原生的 html 项目,所以有很多挂载在 window 上的属性以及方法 其中有一个鼠标事件处理的问题

  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 并且控制台报错了

helpers.ts:122 Uncaught TypeError: Failed to construct 'MouseEvent': Failed to read the 'view' property from 'UIEventInit': Failed to convert value to 'Window'.

按 gpt 改成 globalThis 也无法解决,不是很理解报错的原因以及解决方案,有没有大佬赐教一下

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.