fix(demo): multi-modal used with dynamic component
修复以动态组件的方式使用多个modal的演示
This commit is contained in:
parent
956ed2e3f7
commit
e1c47233ed
|
|
@ -1,10 +1,15 @@
|
||||||
<template>
|
<template>
|
||||||
<BasicModal v-bind="$attrs" @register="register" title="Modal Title">
|
<BasicModal
|
||||||
|
v-bind="$attrs"
|
||||||
|
@register="register"
|
||||||
|
title="Modal Title"
|
||||||
|
@visible-change="handleVisibleChange"
|
||||||
|
>
|
||||||
<BasicForm @register="registerForm" :model="model" />
|
<BasicForm @register="registerForm" :model="model" />
|
||||||
</BasicModal>
|
</BasicModal>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, ref } from 'vue';
|
import { defineComponent, ref, nextTick } from 'vue';
|
||||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
||||||
const schemas: FormSchema[] = [
|
const schemas: FormSchema[] = [
|
||||||
|
|
@ -13,7 +18,7 @@
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
label: '字段1',
|
label: '字段1',
|
||||||
colProps: {
|
colProps: {
|
||||||
span: 12,
|
span: 24,
|
||||||
},
|
},
|
||||||
defaultValue: '111',
|
defaultValue: '111',
|
||||||
},
|
},
|
||||||
|
|
@ -22,13 +27,16 @@
|
||||||
component: 'Input',
|
component: 'Input',
|
||||||
label: '字段2',
|
label: '字段2',
|
||||||
colProps: {
|
colProps: {
|
||||||
span: 12,
|
span: 24,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { BasicModal, BasicForm },
|
components: { BasicModal, BasicForm },
|
||||||
setup() {
|
props: {
|
||||||
|
userData: { type: Object },
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
const modelRef = ref({});
|
const modelRef = ref({});
|
||||||
const [
|
const [
|
||||||
registerForm,
|
registerForm,
|
||||||
|
|
@ -46,20 +54,30 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const [register] = useModalInner((data) => {
|
const [register] = useModalInner((data) => {
|
||||||
// 方式1
|
data && onDataReceive(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
function onDataReceive(data) {
|
||||||
|
console.log('Data Received', data);
|
||||||
|
// 方式1;
|
||||||
// setFieldsValue({
|
// setFieldsValue({
|
||||||
// field2: data.data,
|
// field2: data.data,
|
||||||
// field1: data.info,
|
// field1: data.info,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// 方式2
|
// // 方式2
|
||||||
modelRef.value = { field2: data.data, field1: data.info };
|
modelRef.value = { field2: data.data, field1: data.info };
|
||||||
|
|
||||||
// setProps({
|
// setProps({
|
||||||
// model:{ field2: data.data, field1: data.info }
|
// model:{ field2: data.data, field1: data.info }
|
||||||
// })
|
// })
|
||||||
});
|
}
|
||||||
return { register, schemas, registerForm, model: modelRef };
|
|
||||||
|
function handleVisibleChange(v) {
|
||||||
|
v && props.userData && nextTick(() => onDataReceive(props.userData));
|
||||||
|
}
|
||||||
|
|
||||||
|
return { register, schemas, registerForm, model: modelRef, handleVisibleChange };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
<a-button type="primary" class="my-4" @click="openTargetModal(4)"> 打开弹窗4 </a-button>
|
<a-button type="primary" class="my-4" @click="openTargetModal(4)"> 打开弹窗4 </a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
|
|
||||||
<component :is="currentModal" @register="register" />
|
<component :is="currentModal" v-model:visible="modalVisible" :userData="userData" />
|
||||||
|
|
||||||
<Modal1 @register="register1" :minHeight="100" />
|
<Modal1 @register="register1" :minHeight="100" />
|
||||||
<Modal2 @register="register2" />
|
<Modal2 @register="register2" />
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, nextTick, shallowRef, ComponentOptions } from 'vue';
|
import { defineComponent, shallowRef, ComponentOptions, ref, nextTick } from 'vue';
|
||||||
import { Alert, Space } from 'ant-design-vue';
|
import { Alert, Space } from 'ant-design-vue';
|
||||||
import { useModal } from '/@/components/Modal';
|
import { useModal } from '/@/components/Modal';
|
||||||
import Modal1 from './Modal1.vue';
|
import Modal1 from './Modal1.vue';
|
||||||
|
|
@ -51,7 +51,9 @@
|
||||||
const [register2, { openModal: openModal2 }] = useModal();
|
const [register2, { openModal: openModal2 }] = useModal();
|
||||||
const [register3, { openModal: openModal3 }] = useModal();
|
const [register3, { openModal: openModal3 }] = useModal();
|
||||||
const [register4, { openModal: openModal4 }] = useModal();
|
const [register4, { openModal: openModal4 }] = useModal();
|
||||||
const [register, { openModal }] = useModal();
|
const modalVisible = ref<Boolean>(false);
|
||||||
|
const userData = ref<any>(null);
|
||||||
|
|
||||||
function send() {
|
function send() {
|
||||||
openModal4(true, {
|
openModal4(true, {
|
||||||
data: 'content',
|
data: 'content',
|
||||||
|
|
@ -82,7 +84,11 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
openModal(true, { data: 'content', info: 'Info' });
|
// `useModal` not working with dynamic component
|
||||||
|
// passing data through `userData` prop
|
||||||
|
userData.value = { data: Math.random(), info: 'Info222' };
|
||||||
|
// open the target modal
|
||||||
|
modalVisible.value = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +101,8 @@
|
||||||
openModal3,
|
openModal3,
|
||||||
register4,
|
register4,
|
||||||
openModal4,
|
openModal4,
|
||||||
register,
|
modalVisible,
|
||||||
|
userData,
|
||||||
openTargetModal,
|
openTargetModal,
|
||||||
send,
|
send,
|
||||||
currentModal,
|
currentModal,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue