【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

相关推荐

  1. iOS app切换后台时添加模糊

    2024-04-27 06:36:05       37 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-27 06:36:05       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-27 06:36:05       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-27 06:36:05       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-27 06:36:05       18 阅读

热门阅读

  1. day03--react中setState的使用

    2024-04-27 06:36:05       13 阅读
  2. linux安装opencv

    2024-04-27 06:36:05       14 阅读
  3. Kafka

    Kafka

    2024-04-27 06:36:05      12 阅读
  4. js的基础知识

    2024-04-27 06:36:05       12 阅读
  5. 【动态规划】Leetcode 416. 分割等和子集【中等】

    2024-04-27 06:36:05       12 阅读
  6. Jsoup爬虫

    2024-04-27 06:36:05       12 阅读
  7. 快速使用之Log4j2日志框架

    2024-04-27 06:36:05       10 阅读