Skip to content
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

feat(vue): init vue ui binding #2775

Merged
merged 13 commits into from
Dec 5, 2023
Merged

Conversation

linghaoSu
Copy link

resolve #2689

MicroApp 组件

直接通过 组件加载(或卸载)子应用,该组件提供了 loading 以及错误捕获相关的能力:

<script setup>
import { MicroApp } from '@qiankunjs/vue';

</script>
<template>
  <micro-app name="app1" entry="http://localhost:8000" />
</template>

当启用子应用加载动画或错误捕获能力时,子应用接受一个额外的样式类 wrapperClassName,渲染的结果如下所示:

<div :class="wrapperClassName">
  <MicroAppLoader :loading="loading" />
  <ErrorBoundary :error="e" />
  <MicroApp :class="className" />
</div>

加载动画

启用此能力后,当子应用正在加载时,会自动显示加载动画。当子应用挂载完成变成 MOUNTED 状态时,加载状态结束,显示子应用内容。

直接将 autoSetLoading 作为参数传入即可:

<script setup>
import { MicroApp } from '@qiankunjs/vue';

</script>
<template>
  <micro-app name="app1" entry="http://localhost:8000" autoSetLoading />
</template>

自定义加载动画

如果您希望覆盖默认的加载动画样式时,可以通过 loader slot 来自定义加载组件 loader 作为子应用的加载动画。

<script setup>
import CustomLoader from '@/components/CustomLoader.vue';
import { MicroApp } from '@qiankunjs/vue';

</script>
<template>
  <micro-app name="app1" entry="http://localhost:8000" >
     <template #loader="{ loading }">
       <custom-loader :loading="loading">
     </template>
  </micro-app>
</template>

其中,loading 为 boolean 类型参数,为 true 时表示仍在加载状态,为 false 时表示加载状态已结束。

错误捕获

启用此能力后,当子应用加载出现异常时,会自动显示错误信息。可以向子应用传入 autoCaptureError 属性以开启子应用错误捕获能力:

<script setup>
import { MicroApp } from '@qiankunjs/vue';

</script>
<template>
  <micro-app name="app1" entry="http://localhost:8000" autoCaptureError />
</template>

自定义错误捕获

如果您希望覆盖默认的错误捕获组件样式时,可以通过 errorBoundary slot 来自定义子应用的错误捕获组件:

<script setup>
import CustomErrorBoundary from '@/components/CustomErrorBoundary.vue';
import { MicroApp } from '@qiankunjs/vue';

</script>
<template>
  <micro-app name="app1" entry="http://localhost:8000" >
     <template #error-boundary="{ error }">
       <custom-error-boundary :error="error">
     </template>
  </micro-app>
</template>

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2023

⚠️ No Changeset found

Latest commit: b496697

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 30, 2023

@linghaoSu is attempting to deploy a commit to a Personal Account owned by @umijs on Vercel.

@umijs first needs to authorize it.

@linghaoSu linghaoSu force-pushed the feat/vue-ui-binding branch 2 times, most recently from 5277679 to cd3087b Compare October 31, 2023 15:21
@kuitos kuitos requested a review from bravepg November 8, 2023 03:38
@kuitos
Copy link
Member

kuitos commented Nov 8, 2023

@bravepg 可以一起 review 下

@linghaoSu linghaoSu force-pushed the feat/vue-ui-binding branch 2 times, most recently from de440e0 to 1da18bf Compare November 8, 2023 15:01
@bravepg
Copy link
Contributor

bravepg commented Nov 8, 2023

@bravepg 可以一起 review 下

好的,前几天忙着其他事忘记这个 pr 了😂,我看看

"dev": "father dev",
"test": "cross-env NODE_ENV=test vitest"
},
"author": "Bravepg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

author 换成你吧~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换了~

container: containerRef.current!,
props: propsFromParams,
mountMicroApp({
props: componentProps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有点怪,把 componentProps 这个全部属性都透传进去了,然后下面又传递了 propsFromParams

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

setLoading(loading);
},
source: 'react',
})

return noop;
}, [useDeepCompare(propsFromParams)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有个风险,lifeCycles 是个函数数组,之前是解构出来了。现在被放进到 propsFromParams 里面,如果有户有个设置生命周期的操作,可能会造成无限更新,最好还是把初始化需要的一些变量给解构出来。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果会无限更新应该在 vue 中也会,统一做一次 omit 解构

setLoading: (loading) => {
setLoading(loading);
},
source: 'react',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source 换个名字吧,有点怪怪的。可以直接叫做 key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好主意,换了

props: componentProps,
container: containerRef.current!,
propsFromParams,
setApp(app) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setApp getApp,换成 setMicroApp 和 getMicroApp 吧

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

props: {
name: {
type: String,
required: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vue 里面的 props 类型得重新定义一遍么?有没有快捷的生成方式?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vue 3.3 的 SFC 写法支持 通过 类型 来直接声明 props,但是目前 father 这个库似乎还不支持 compile vue 文件,因此目前还没想到更好的方式

或者将 vue 的 PropType 和 ExtractPropType 在 shared 中实现一边,并且使用此处的 props 作为基础,生成 sharedProps 类型

image

watch(
name,
() => {
const microApp = microAppRef.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初始化的时候,有必要判断 microApp 是否存在吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是 watch 启动后,当 name 发生变化时,销毁之前的生成的 microApp 用的判断

</script>

<template>
<MicroApp :name="name" entry="//localhost:7102" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

examples 这么搞合适吗?未来可能有很多个案例,有规划怎么展示给用户吗?单独叫 main-vue 然后引入 MicroApp 是不是有点重了。
@kuitos

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里只是为了验证 vue 组件的可用,加入的 实验 demo,如果后续不需要可以在合并之前删掉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuitos 其他的我 ok 了,这块 examples 的形式你确认下?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不同单独搞一个仓库,参考现在的 main https://github.com/umijs/qiankun/blob/master/examples/main/render/VueRender.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正在处理中,稍后提交更新

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuitos 在处理 demo 的过程中,发现目前的做法仅兼容 vue3,是否需要兼容到 vue2?

目前正在尝试使用 vue-demi 来做兼容处理,但需要一点时间,我先标记为 Draft 了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kuitos fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demi 应该也是只能兼容到2.7+吧

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

<= 2.6 通过 @vue/composition-api 来进行兼容

如果项目中未安装,则会提示安装
image

@linghaoSu linghaoSu requested a review from bravepg November 13, 2023 13:16
@linghaoSu linghaoSu marked this pull request as ready for review November 15, 2023 01:18
@linghaoSu linghaoSu marked this pull request as draft November 24, 2023 01:05
@linghaoSu linghaoSu marked this pull request as ready for review November 27, 2023 14:58
@linghaoSu linghaoSu requested a review from kuitos November 27, 2023 14:59
MicroApp-bak Outdated Show resolved Hide resolved
@linghaoSu linghaoSu requested a review from kuitos November 28, 2023 09:07
@kuitos kuitos requested a review from gongshun November 28, 2023 13:20
@kuitos
Copy link
Member

kuitos commented Nov 28, 2023

ci 需要修一下

@linghaoSu
Copy link
Author

linghaoSu commented Nov 29, 2023

ci 需要修一下

@kuitos fixed

@kuitos kuitos merged commit fdb5f8a into umijs:next Dec 5, 2023
5 checks passed
@kuitos kuitos linked an issue Feb 26, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] 配套的 UI Library(Vue 版本)
4 participants