Coder Social home page Coder Social logo

有没有大佬写过这种, 基座应用为vite + vue3, 多页签的应用, 多个子应用也是vite+vue3, 基座应用左侧配置, 子应用的菜单,有大佬提供demo吗, 不胜感激 about micro-app HOT 1 OPEN

mzcc666GtHb avatar mzcc666GtHb commented on August 29, 2024
有没有大佬写过这种, 基座应用为vite + vue3, 多页签的应用, 多个子应用也是vite+vue3, 基座应用左侧配置, 子应用的菜单,有大佬提供demo吗, 不胜感激

from micro-app.

Comments (1)

liuxiucai avatar liuxiucai commented on August 29, 2024

@mzcc666GtHb 官方例子中已经有这类demo

大体的思路,主应用左侧的菜单配置子应用的路径信息(主要是path),主应用通过 消息的形式把路径信息发送给 子应用,子应用接受之后,使用自身的router进行页面的跳转。

  1. vite+vue3 的主应用 建立消息通行 与 发生路径
      // 主应用通过下发data数据控制子应用跳转
      microApp.setData(appName, { path: childPath })
import { EventCenterForMicroApp } from '@micro-zoe/micro-app'
// @ts-ignore 因为vite子应用关闭了沙箱,我们需要为子应用appname-vite创建EventCenterForMicroApp对象来实现数据通信
window.eventCenterForAppNameVite = new EventCenterForMicroApp('appname-vite')
  1. 子应用接受路径消息跳转

更多详情

    // 监听基座下发的数据变化
    window.eventCenterForAppNameVite.addDataListener((data: Record<string, unknown>) => {
      console.log('child-vite addDataListener:', data)

      if (data.path && typeof data.path === 'string') {
        data.path = data.path.replace(/^#/, '')
        // 当基座下发path时进行跳转
        if (data.path && data.path !== router.currentRoute.value.path) {
          router.push(data.path as string)
        }
      }
    })

from micro-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.