Replies: 4 comments 2 replies
-
Modal应该要能通过组件/子组件方式调用,保证灵活性,这是基础形态,基于此可以提供service调用方式,提升开发者体验。 |
Beta Was this translation helpful? Give feedback.
-
modal 组件如何按需引入,按照文档提示: DIALOG_SERVICE_TOKEN 找不到 |
Beta Was this translation helpful? Give feedback.
-
modal 按需引入运行失败,全局引入后,运行成功。我应该如何操作? |
Beta Was this translation helpful? Give feedback.
-
Modal优化草案Modal 组件使用通过子组件+插槽的方式,子组件暂时提供 d-modal 参数
d-modal 插槽
基础用法
<template>
<d-button @click="handleClick">打开 modal</d-button>
<d-modal v-model="visible" title="Start Snapshot Version">
<div>name: {{ data.name }}</div>
<div>age: {{ data.age }}</div>
<div>address: {{ data.address }}</div>
</d-modal>
</template>
<script>
import { defineComponent, ref, reactive } from 'vue';
export default defineComponent({
setup() {
const visible = ref(false);
const data = reactive({
name: 'Tom',
age: 20,
address: 'Chengdu'
});
const handleClick = () => {
visible.value = true;
};
return { visible, data, handleClick };
}
});
</script> 自定义标题和操作按钮
<template>
<d-button @click="handleClick">打开 modal</d-button>
<d-modal v-model="visible">
<template #header>
<d-modal-header>
<d-icon name="like"></d-icon>
<span>Good Title</span>
</d-modal-header>
</template>
<div>name: {{ data.name }}</div>
<div>age: {{ data.age }}</div>
<div>address: {{ data.address }}</div>
<template #footer>
<d-modal-footer style="text-align: right;padding-right: 20px;">
<d-button @click="hidden">取消</d-button>
<d-button @click="hidden">确认</d-button>
</d-modal-footer>
</template>
</d-modal>
</template>
<script>
import { defineComponent, ref, reactive } from 'vue';
export default defineComponent({
setup() {
const visible = ref(false);
const data = reactive({
name: 'Tom',
age: 20,
address: 'Chengdu'
});
const handleClick = () => {
visible.value = true;
};
const hidden = () => {
visible.value = false;
};
return { visible, data, handleClick, hidden };
}
});
</script> 关闭前回调
<template>
<d-button @click="handleClick">打开 modal</d-button>
<d-modal v-model="visible" :before-close="beforeClose" style="width: 500px;">
<div>name: {{ data.name }}</div>
<div>age: {{ data.age }}</div>
<div>address: {{ data.address }}</div>
<template #footer>
<d-modal-footer>
<d-button @click="hidden">取消</d-button>
<d-button @click="hidden">确认</d-button>
</d-modal-footer>
</template>
</d-modal>
</template>
<script>
import { defineComponent, ref, reactive } from 'vue';
export default defineComponent({
setup() {
const visible = ref(false);
const data = reactive({
name: 'Tom',
age: 20,
address: 'Chengdu'
});
const handleClick = () => {
visible.value = true;
};
const hidden = () => {
visible.value = false;
};
const beforeClose = (done) => {
new Promise((resolve) => {
setTimeout(resolve, 1000);
}).then(done);
};
return { data, visible, handleClick, hidden, beforeClose };
}
});
</script> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
api
Modal组件:https://vue-devui.github.io/components/modal/
Beta Was this translation helpful? Give feedback.
All reactions