-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cd1ad4
commit 3e18778
Showing
8 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { RouteRecordRaw } from 'vue-router'; | ||
export const routes: RouteRecordRaw[] = [ | ||
{ | ||
path: 'service', | ||
component: () => import('@/views/example/service/index.vue'), | ||
meta: { title: '函数式组件(动态组件方式生成)' }, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useGlobalStore } from '@/store'; | ||
import Add from './add.vue'; | ||
export default async (props: Omit<ComponentProps<typeof Add>, 'show'> = {}) => { | ||
const show = ref(true); | ||
const globalStore = useGlobalStore(); | ||
const key = globalStore.addGlobalComponents( | ||
Add, | ||
computed(() => ({ | ||
show: show.value, | ||
...props, | ||
['onUpdate:show']: (value: boolean) => { | ||
show.value = value; | ||
}, | ||
onClosed: () => { | ||
globalStore.removeGlobalComponents(key); //关闭时移除当前组件 | ||
props.onClosed && props.onClosed(); | ||
}, | ||
})), | ||
); | ||
await nextTick(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<el-dialog v-model="show" @closed="$emit('closed')"> | ||
<div>这是测试弹窗 <el-button @click="add()"> 再次打开弹窗 </el-button></div> | ||
</el-dialog> | ||
</template> | ||
|
||
<script setup lang="ts" name="Add"> | ||
import add from './add'; | ||
const show = defineModel<boolean>('show'); | ||
defineEmits<{ closed: [] }>(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<div class="index"> | ||
点击按钮,将以函数调用方式打开组件,函数调用组件会渲染到body中。 设计成动态组件方式而非vnode方式是因为vnode插入方式脱离当前app根组件,无法使用vue-deetools调试 | ||
<br /> | ||
<el-button @click="add()"> 以函数方式打开弹窗</el-button> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts" name="Index"> | ||
import add from './components/add'; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters