antd Popover 氣泡卡片動(dòng)態(tài)內(nèi)容,首次位置不對(duì)解決方法

在表格中,移動(dòng)到上面時(shí),懸浮顯示說(shuō)明,首次移入時(shí)加載,想要效果如下圖:

image.png

發(fā)現(xiàn)首次移入時(shí),位置偏移了,這就挺鬧心的

image.png

網(wǎng)上的解決方案是固定大小,但是對(duì)應(yīng)動(dòng)態(tài)內(nèi)容是不適合的,自己使用定時(shí)器解決,代碼如下:

<template>
  <a-popover placement="top"
             overlayClassName="tagPopover"
             :visible="popoverVisible"
             @visibleChange="(visible) =>init(visible)"
             :get-popup-container="getPopupContainer"
  >
    <template slot="content">
      <template v-for="(item, index) in reason">
        <div style="font-size: 12px;">{{ item.name }}({{ item.value }})</div>
      </template>
    </template>
    <span>{{ text ? text : '-' }}</span>
  </a-popover>
</template>

<script>
export default {
  name: 'AdjustmentTag',
  data() {
    return {
      popoverVisible: false
    }
  },
  props: {
    text: {
      type: Number,
      required: false
    },
    reason: {
      type: Array,
      required: false
    }
  },
  methods: {
    getPopupContainer(trigger) {
      return trigger.parentElement;
    },
    init(visible) {
      if(visible){
        const _this = this
        if (!this.reason) {
          visible = false
          setTimeout(function() {
            _this.popoverVisible = true
          }, 50)
          this.$emit('initData')
        }else {
          this.popoverVisible = true
        }
      } else {
        this.popoverVisible = false
      }
    }
  },
  mounted() {}
}
</script>

<style scoped>

</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過(guò)簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容