antd 关闭弹窗组件后再次打开里面还有上次的值

在Vue3中集成Ant Design的Modal组件并添加内部路由,通常是在需要在一个可关闭弹窗里展示完整的子页面功能时使用。以下是基本步骤: 1. 首先,你需要安装Ant Design Vue和Vue Router库,如果还没安装可以使用`npm install ant-design-vue@latest vue-router@latest`。 2. 在Vue组件中引入必要的模块: ```javascript import { Modal } from 'ant-design-vue'; import { useRouter } from 'vue-router'; ``` 3. 创建一个可复用的Modal组件,比如`ModalWithRoute.vue`,这里包含路由切换: ```html <template> <Modal v-model="visible" @on-ok="handleOk"> <router-view></router-view> </Modal> </template> <script> export default { name: 'ModalWithRoute', props: { visible: { type: Boolean, default: false, }, }, methods: { handleOk() { // 当点击确认按钮时,关闭Modal并执行路由跳转(假设你有一个名为'/detail'的路径) this.$router.push('/detail'); this.$emit('ok', this.$router.currentRoute.fullPath); // 返回当前路由路径给外部组件 }, }, }; </script> ``` 4. 在需要显示路由的父组件中使用这个Modal组件,并设置它的可见状态: ```html <template> <button @click="openModal">打开带路由的Modal</button> <ModalWithRoute :visible.sync="modalVisible" @ok="handleClose"></ModalWithRoute> </template> <script> import ModalWithRoute from './components/ModalWithRoute.vue'; export default { components: { ModalWithRoute, }, data() { return { modalVisible: false, }; }, methods: { openModal() { this.modalVisible = true; }, handleClose(path) { this.modalVisible = false; // 关闭Modal // 如果需要,你也可以在这里处理返回的路径 }, }, }; </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值