【Vant组件】van-dialog组件弹窗只有遮罩层不显示内容解决方案

项目场景:

移动端引用Vant组件Popup 弹出层 van-dialog,只显示遮罩层而不显示内容。


问题描述

移动端引用van-dialog 组件做弹出层显示内容,只显示遮罩层而不显示内容。

vue中代码如下

    <van-dialog v-model="popShow" :title="showTextTitle"
                confirm-button-color="#1e87f0"
                confirmButtonText="确定"
                @confirm="Confirm"
                @cancel="Cancel" show-cancel-button>
      <div style="height: 100%;max-height:500px;overflow: scroll">
       内容111
      </div>
    </van-dialog>

原因分析:

未指定挂载位置可能导致内容不显示

由于未指定组件 van-dialog 出现位置导致内容不显示。


解决方案:

指定弹出层挂载位置:弹出层默认挂载到组件所在位置,可以通过 get-container 属性指定挂载位置。

在这里插入图片描述



<!-- 挂载到 body 节点下 -->
<van-popup v-model="show" get-container="body" />

<!-- 挂载到 #app 节点下 -->
<van-popup v-model="show" get-container="#app" />

<!-- 通过函数指定挂载位置 -->
<van-popup v-model="show" :get-container="getContainer" />
export default {
  methods: {
    // 返回一个特定的 DOM 节点,作为挂载的父节点
    getContainer() {
      return document.querySelector('.my-container');
    },
  },
};

添加 get-container="body" 最后代码如下:

    <van-dialog v-model="popShow" :title="showTextTitle"
                get-container="body"
                confirm-button-color="#1e87f0"
                confirmButtonText="确定"
                @confirm="Confirm"
                @cancel="Cancel" show-cancel-button>
      <div style="height: 100%;max-height:500px;overflow: scroll">
       内容111
      </div>
    </van-dialog>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值