Yb-components Yb-components
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
首页
开发规范
yb-cli
  • 开发指南
  • 更新日志
  • 组件
关于
  • 开发指南
  • 更新日志
  • 数据展示

    • YbTable 表格
    • YbCardList 卡片列表
    • YbTree 树
    • YbCascaderList 级联列表
    • YbSimpleTablePage 分页查询表格
    • YbSimpleCardPage 分页卡片列表
    • YbBasicProfile 基础详情数据展示
    • YbOutscrollLayout 固定在滚动区域外
    • YbOutscrollTree 固定在滚动区域外的Tree
    • YbInfoLayout 信息页布局
    • YbEditLayout 编辑页布局
  • 数据录入

    • YbRowsPopoverForm 浮层多行表单
    • YbFormily 配置式表单
    • YbForm 表单
    • YbRowsForm 多行表单
    • YbCollapseForm 折叠表单
    • YbQueryFilter 筛选表单
    • YbFilesSelect 文件选择器
    • YbRangeWrapper 范围结构
    • YbRangeDatepicker 日期范围
    • YbRange 范围
    • YbFormulaInput 简单运算公式输入
    • YbCron 表达式生成器
    • YbTreeSelect 树型选择器
    • YbInputgroupWrapper 复合组
    • YbThemeSelect 主题风格选择器
    • YbSelect 选择器
    • YbPaginationSelect 分页选择器
    • YbCodemirror 代码编辑器
    • YbCodemirrorSql SQL编辑器
    • YbCodemirrorJson JSON编辑器
    • YbCodemirrorXml XML编辑器
    • YbCombiDatepicker 组合时间
    • YbQuarterPicker 季度选择器
    • YbRangeQuarterPicker 季度范围选择器
    • YbConditionSelect 条件选择器
    • YbCheckboxGroup 多选框组
    • YbIconSelect 选择器
    • YbTagsInput 标签输入框
  • 其他组件

    • YbBallLoading 加载中
    • YbSymbolIcon 多色小图标
    • YbKeybuttonsPopover
    • YbPercentBattery 电池百分比
    • YbAffix 固钉
    • YbPagination 分页器
    • YbCollapse 折叠面板
    • YbScrollTool 滚动工具
  • 物料

    • YbMainSideMenu 侧栏菜单
    • YbLoadRemote 远程应用加载
      • YbLayoutPro 布局
      • YbMainPro 主页
      • YbAppMain 应用主页
      • YbAppLogin 普通登录页
      • YbAppPortal Portal登录页
    • 指令

      • v-fixed-in-scroller
    • Mixins

      • pageList_mixin
      • getScopedSlot_mixin
      • editFormPage_mixin
      • uploadProgressPage_mixin
      • rowActions_mixin
      • rowDeletes_mixin
      • drawerToRouterTab_mixin
    • 实验室

      • YbSwiper 轮播
    • 组件
    • 物料
    zougt
    2021-10-14

    YbLoadRemote 远程应用加载

    此文档未完善

    非 iframe 方式,获取地址栏对应的参数加载远程子应用(可跨域)

    前提条件:使用 webpack5 的模块联邦构建出 remote-entry.js(默认)的子应用,并且地址栏存在_remote_src(remoteSrcKey 的默认值)和_remote_scope_name(remoteScopeNameKey 的默认值)参数

    webpack5 模块联邦插件配置 (最新的 yb-cli 创建的 web 工程已默认配置)

    const { ModuleFederationPlugin } = webpack.container;
    
    const moduleScropeName = 'my_child_app';
    module.exports = {
        entry: './src/entry.js',
        plugins: [
            new ModuleFederationPlugin({
                name: moduleScropeName,
                library: { type: 'var', name: moduleScropeName },
                // 可变
                filename: 'remote-entry.js',
                // 在YbLoadeRemote中模块名称默认是 './app'
                exposes: {
                    './app': './src/app.js',
                },
                // 可变
                shared: ['vue', 'vue-router', 'vue-router-tab', 'core-js'],
            }),
        ],
    };
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    /* ./src/app.js */
    /**
     * app.js除了在main.js创建vue实例,也用于webpack5的模块联邦打包后会生成一个 remote-entry.js
     */
    import Vue from 'vue';
    import App from './App.vue';
    let vueInstance = null;
    function createApp(options) {
        vueInstance = new Vue({
            render() {
                return <App />;
            },
        }).$mount(options.rootElement);
        return Promise.resolve({
            appInstance: vueInstance,
            rootEl: vueInstance.$el,
        });
    }
    function destroyApp() {
        if (vueInstance) {
            vueInstance.$destroy();
            vueInstance = null;
        }
        return Promise.resolve();
    }
    export { createApp, destroyApp };
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    /* ./src/webpack-entry.js */
    import('./main');
    
    1
    2
    /* ./src/main.js */
    import { createApp } from './app.js';
    createApp({
        rootElement: '#app',
    });
    
    1
    2
    3
    4
    5

    # 基本用法

    需要在这测试加载案例的前提

    # 使用yb-cli创建一个web工程
    npx yb-cli init medical-calculate-web
    
    # 进入medical-calculate-web后打包
    npm run build
    cd dist
    npx http-server
    # 可能得到如下地址
    Available on:
      http://127.0.0.1:8081
      http://192.168.1.112:8081
    Hit CTRL-C to stop the server
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    之后可以当前浏览器地址栏添加参数例如
    ?_remote_src="http://192.168.1.112:8081"&_remote_scope_name=medical_calculate_web 回车就能加载

    <template>
        <div style="height:50vh;display:flex;flex-direction: column;">
            <yb-load-remote
                remoteAppRouterBasepath="/pages/components/YbLoadRemote"
                :remoteAppProvideData="remoteAppProvideData"
            />
        </div>
    </template>
    
    <script>
        export default {
            name: 'layout-route-remote',
            data() {
                return {
                    remoteAppProvideData: {
                        hideAppHeader: true,
                    },
                };
            },
            provide() {
                return {
                    parentAppUrlQuery: {},
                };
            },
        };
    </script>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    显示 复制 复制

    # props

    参数 说明 类型 可选值 默认值
    remoteAppProvideState 传递给子应用的状态,在子应用中接收后不应该改变原对象情况,父应用对状态改变,能够实时响应 object - {}
    remoteAppProvideData 传递给子应用的数据,在子应用中接收后可以改变原对象 object - {}
    remoteAppRouterBasepath 子应用路由的基础路径,在使用 yb-load-remote 的所在路由配置的 path 对应即可 string - '/remoteApp'
    remoteSrcKey url 参数的 key,用于获取子应用的 remote-entry.js 的路径 string - '_remote_src'
    remoteScopeNameKey url 参数的 key,用于获取加载子应用 app 模块的作用域名称 string - '_remote_scope_name'
    remoteModuleNameKey url 参数的 key,用于获取加载子应用模块的名称(默认是"./app")称 string - '_remote_module_name'
    上次更新: 2024/02/28, 17:31:26
    YbMainSideMenu 侧栏菜单
    YbLayoutPro 布局

    ← YbMainSideMenu 侧栏菜单 YbLayoutPro 布局→

    Theme by Vdoing | Copyright © 2021-2025 YB-GZ | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式