【bug】vuxUI组件popup弹出框在IOS中遮罩层会遮住页面

可以增加自定义方法v-transfer-dom

   <div v-transfer-dom="true">
      <Popup v-model="showPopup">
        <PopupHeader :title="policyloan.docJson.title" />
        <div class="noticeText">
          <p v-for="(item, index) in policyloan.docJson.contents" :key="index" :class="item.class">
            {{ item.content }}
          </p>
        </div>
        <PopupFooter
          :class="policyloan.countdown ? 'popupFooterDisabled' : ''"
          @onConfirm="onConfirm()"
        >
          {{ policyloan.countdown ? `已阅读(${policyloan.countdown})` : '已阅读' }}
        </PopupFooter>
      </Popup>
    </div>
    import TransferDom from '@/transfer-dom'
    

transfer-dom’.js



const objectAssign = require('object-assign')
/**
 * Get target DOM Node
 * @param {(Node|string|Boolean)} [node=document.body] DOM Node, CSS selector, or Boolean
 * @return {Node} The target that the el will be appended to
 */
function getTarget (node) {
  if (node === void 0) {
    return document.body
  }

  if (typeof node === 'string' && node.indexOf('?') === 0) {
    return document.body
  } else if (typeof node === 'string' && node.indexOf('?') > 0) {
    node = node.split('?')[0]
  }

  if (node === 'body' || node === true) {
    return document.body
  }

  return node instanceof window.Node ? node : document.querySelector(node)
}

function getShouldUpdate (node) {
  // do not updated by default
  if (!node) {
    return false
  }
  if (typeof node === 'string' && node.indexOf('?') > 0) {
    try {
      const config = JSON.parse(node.split('?')[1])
      return config.autoUpdate || false
    } catch (e) {
      return false
    }
  }
  return false
}

const directive = {
  inserted (el, { value }, vnode) {
    el.className = el.className ? el.className + ' v-transfer-dom' : 'v-transfer-dom'
    const parentNode = el.parentNode
    var home = document.createComment('')
    var hasMovedOut = false

    if (value !== false) {
      parentNode.replaceChild(home, el) // moving out, el is no longer in the document
      getTarget(value).appendChild(el) // moving into new place
      hasMovedOut = true
    }
    if (!el.__transferDomData) {
      el.__transferDomData = {
        parentNode: parentNode,
        home: home,
        target: getTarget(value),
        hasMovedOut: hasMovedOut
      }
    }
  },
  componentUpdated (el, { value }) {
    const shouldUpdate = getShouldUpdate(value)
    if (!shouldUpdate) {
      return
    }
    // need to make sure children are done updating (vs. `update`)
    var ref$1 = el.__transferDomData
    // homes.get(el)
    var parentNode = ref$1.parentNode
    var home = ref$1.home
    var hasMovedOut = ref$1.hasMovedOut // recall where home is

    if (!hasMovedOut && value) {
      // remove from document and leave placeholder
      parentNode.replaceChild(home, el)
      // append to target
      getTarget(value).appendChild(el)
      el.__transferDomData = objectAssign({}, el.__transferDomData, { hasMovedOut: true, target: getTarget(value) })
    } else if (hasMovedOut && value === false) {
      // previously moved, coming back home
      parentNode.replaceChild(el, home)
      el.__transferDomData = objectAssign({}, el.__transferDomData, { hasMovedOut: false, target: getTarget(value) })
    } else if (value) {
      // already moved, going somewhere else
      getTarget(value).appendChild(el)
    }
  },
  unbind: function unbind (el, binding) {
    el.className = el.className.replace('v-transfer-dom', '')
    if (el.__transferDomData && el.__transferDomData.hasMovedOut === true) {
      el.__transferDomData.parentNode && el.__transferDomData.parentNode.appendChild(el)
    }
    el.__transferDomData = null
  }
}

export default directive

// Thanks to: https://github.com/calebroseland/vue-dom-portal

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在微信小程序使用 Vant UI弹出弹出,需要进行以下步骤: 1. 安装 Vant UI 库 使用 npm 安装 Vant UI 库: ``` npm i vant-weapp -S --production ``` 2. 引入弹出弹出组件 在需要使用弹出弹出页面,引入 Vant UI弹出弹出组件: ```javascript import { Dialog, Popup } from 'vant-weapp'; ``` 3. 在页面使用弹出弹出页面使用弹出弹出组件,例如: ```html <!-- 弹出 --> <van-dialog id="my-dialog" title="标题" show="{{ isShow }}"> <view>这是弹出内容</view> </van-dialog> <!-- 弹出 --> <van-popup id="my-popup" title="标题" show="{{ isShow }}"> <view>这是弹出内容</view> </van-popup> ``` 其,`isShow` 为控制弹出弹出显示的变量,需要在页面的 `data` 定义和初始化。 4. 控制弹出弹出的显示和隐藏 在页面,可以通过修改 `isShow` 变量的值,控制弹出弹出的显示和隐藏,例如: ```javascript // 显示弹出 this.setData({ isShow: true, }); // 隐藏弹出 this.setData({ isShow: false, }); ``` ```javascript // 显示弹出 this.setData({ isShow: true, }); // 隐藏弹出 this.setData({ isShow: false, }); ``` 以上就是在微信小程序使用 Vant UI弹出弹出的步骤和示例。注意,在微信小程序,需要使用 `id` 属性来绑定弹出弹出,同时也需要在页面的 `onLoad` 生命周期,调用 `this.selectComponent` 方法来获取弹出弹出的实例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值