解决ant-design-vue的Modal组件 设置全屏不生效,css样式无法更改

问题环境:

vue:^3.2.21

ant-design-vue:2.2.8


问题描述:

在使用 ant-design-vue 的 Modal 组件,按照官网设置全屏样式不生效,ant-modal样式top值无法覆盖,导致上面空余了一部分。

解决方法:

参考了网上的写法使用官网上给出的API,最终解决方案如下:

官网API:

getContainer指定 Modal 挂载的 HTML 节点(instance): HTMLElement() => document.body

需要在Modal组件外围包裹一层Div,设置ref,完事再使用  getContainer  方法指定节点最终生效

完整代码:

<template>
  <div ref="modalRef">
    <Modal
      v-model:visible="visible"
      title="详情"
      width="100%"
      :get-container="() => $refs.modalRef"
    >
      123123
    </Modal>
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { Modal } from 'ant-design-vue';
  const modalRef = ref();
  let visible = ref(false);
  defineExpose({
    visible,
  });
</script>

<style lang="less" scoped>
  :deep .ant-modal {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  :deep .ant-modal-content {
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  :deep .ant-modal-body {
    flex: 1;
  }

  // 上下两种 那个生效用那个

  ::v-deep(.ant-modal) {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  ::v-deep(.ant-modal-content) {
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  ::v-deep(.ant-modal-body) {
    flex: 1;
  }
</style>

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值