-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
点击不同的菜单显示显示子应用不同页面 #46
Comments
这是一个好问题,后续官方会出专门的demo来指导 假如主应用 有A、B、C三个菜单对应子应用 subapp 的 a、b、c 三个页面 1、子应用如果是运行在单例模式下(做了生命周期适配),那么 A、B、C 菜单对应的主应用的页面中 这样可以共享一个wujie实例,承载子应用js的iframe也实现了共享,不用页面子应用的url不同,切换菜单的过程相当于:销毁当前应用实例 => 同步新路由 => 创建新应用实例 2、子应用如果运行在保活模式下(alive=ture),那么,在主应用的不同页面中 只要 name 相同子应用就不会销毁新建,一直复用之前渲染出来的实例,这个时候怎么办呢,可以采用通信的方式 主应用切换菜单栏的时候调用: bus.$emit('route-change', path) 子应用在app.vue 的 mounted 生命周期可以监听: mounted() {
if (window.__POWERED_BY_WUJIE__) {
window.$wujie.bus.$on("route-change", (path) => {
this.$router.push({ path: `/${path}` });
});
}
}, 3、子应用运行在重建模式下(alive=false && 没有做生命周期适配),按照 1 即可 |
希望出一个demo,目前试了一下保活模式,在主工程中,只有先点击到子应用之后,再点击菜单才能正常切换 |
@ztaom 可能要到周末才能有时间 |
使用第一种方法的话,是不是就需要在主应用中配置多个子应用标签,分别对应主应用的菜单? |
@SericXu 我周末出一个demo哈,不用多个子应用标签,一个子应用标签,动态 url 就好了 |
动态url确实可以,这个我想过,这么一来,是不是我就得在主应用去配置好所有的子应用的路由。总感觉有点别扭,说不出来 XD,等后续我再琢磨琢磨怎么个意思。哈哈 我在想有没有可能实现在主应用打开子应用页面的时候,我传一个router对象或者path之类的参数,使子应用打开指定的页面。这样是不是更方便一点。 |
可以的,直接方式 2 保活模式,主应用直接告诉子应用要怎么跳,子应用根据参数自行跳转,这样也就解耦了 |
@yiludege 我按照demo改了一下,现在初始化第一次点击菜单没问题,再切换另一个菜单vue router会报错,不知是不是版本问题,我用的路由版本vue-router@4.1.3;详情如下:
|
另外,当采用preloadApp的时候,无论preloadApp是否开启保活,WujieVue标签是不是不能再使用alive保活属性? 当我给标签也添加保活属性是,会打开子应用,但是空白,貌似路由没有加在路由上。类似这样的情况: |
demo中,vue3、vite的 router都是4.x的版本,保活模式按照demo即可,单例模式下,window.__WUJIE_MOUNT每次新建路由 |
preloadApp的 url 和 wujie-vue 的 url 保持一致呢? |
以下是我目前的代码,配置基本都和demo一致
|
已解决
|
请问大佬,你这个问题解决了吗?能发一个demo参考一下吗? |
在主工程中,如何通过点击不同的菜单显示显示子工程不同的页面,菜单会添加到多页签中,方便切换
The text was updated successfully, but these errors were encountered: