欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

怎么在Vue中使用Tooltip組件

怎么在Vue中使用Tooltip組件?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)思禮,10年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):18982081108

tooltip

常用于展示鼠標(biāo) hover 時(shí)的提示信息。

模板結(jié)構(gòu)

<template>
 <div >
  <span ref="trigger">
   <slot>
   </slot>
  </span>
  <div class="tooltip"
   v-bind:class="{
    'top':   placement === 'top',
    'left':  placement === 'left',
    'right':  placement === 'right',
    'bottom': placement === 'bottom',
    'disable': type === 'disable',
    'delete': type === 'delete',
    'visible': show === true 
   }"
   ref="popover"
   role="tooltip">
   <div class="tooltip-arrow"></div>
   <div class="tooltip-inner">
    <slot name="content" v-html="content"></slot>
   </div>
  </div>
 </div>
</template>

大致結(jié)構(gòu)DOM結(jié)構(gòu) 一個(gè)div 包含 箭頭 及 氣泡內(nèi)容。

v-bind中可選tooltip位置,是否禁用,及顯示隱藏

slot 差值供自定義 默認(rèn)接收content內(nèi)容

script

import EventListener from '../utils/EventListener.js';

export default {
 props: {
  // 需要監(jiān)聽(tīng)的事件
  trigger: {
   type: String,
   default: 'click'
  },
  effect: {
   type: String,
   default: 'fadein'
  },
  title: {
   type: String
  },
  // toolTip消息提示
  content: {
   type: String
  },
  header: {
   type: Boolean,
   default: true
  },
  placement: {
   type: String
  }
 },
 data() {
  return {
   // 通過(guò)計(jì)算所得 氣泡位置 
   position: {
    top: 0,
    left: 0
   },
   show: true
  };
 },
 watch: {
  show: function(val) {
   if (val) {
    const popover = this.$refs.popover;
    const triger = this.$refs.trigger.children[0];
    // 通過(guò)placement計(jì)算出位子
    switch (this.placement) {
     case 'top' :
      this.position.left = triger.offsetLeft - popover.offsetWidth / 2 + triger.offsetWidth / 2;
      this.position.top = triger.offsetTop - popover.offsetHeight;
      break;
     case 'left':
      this.position.left = triger.offsetLeft - popover.offsetWidth;
      this.position.top = triger.offsetTop + triger.offsetHeight / 2 - popover.offsetHeight / 2;
      break;
     case 'right':
      this.position.left = triger.offsetLeft + triger.offsetWidth;
      this.position.top = triger.offsetTop + triger.offsetHeight / 2 - popover.offsetHeight / 2;
      break;
     case 'bottom':
      this.position.left = triger.offsetLeft - popover.offsetWidth / 2 + triger.offsetWidth / 2;
      this.position.top = triger.offsetTop + triger.offsetHeight;
      break;
     default:
      console.log('Wrong placement prop');
    }
    popover.style.top = this.position.top + 'px';
    popover.style.left = this.position.left + 'px';
   }
  }
 },
 methods: {
  toggle() {
   this.show = !this.show;
  }
 },
 mounted() {
  if (!this.$refs.popover) return console.error("Couldn't find popover ref in your component that uses popoverMixin.");
  // 獲取監(jiān)聽(tīng)對(duì)象
  const triger = this.$refs.trigger.children[0];
  // 根據(jù)trigger監(jiān)聽(tīng)特定事件
  if (this.trigger === 'hover') {
   this._mouseenterEvent = EventListener.listen(triger, 'mouseenter', () => {
    this.show = true;
   });
   this._mouseleaveEvent = EventListener.listen(triger, 'mouseleave', () => {
    this.show = false;
   });
  } else if (this.trigger === 'focus') {
   this._focusEvent = EventListener.listen(triger, 'focus', () => {
    this.show = true;
   });
   this._blurEvent = EventListener.listen(triger, 'blur', () => {
    this.show = false;
   });
  } else {
   this._clickEvent = EventListener.listen(triger, 'click', this.toggle);
  }
  this.show = !this.show;
 },
 // 在組件銷毀前移除監(jiān)聽(tīng),釋放內(nèi)存
 beforeDestroy() {
  if (this._blurEvent) {
   this._blurEvent.remove();
   this._focusEvent.remove();
  }
  if (this._mouseenterEvent) {
   this._mouseenterEvent.remove();
   this._mouseleaveEvent.remove();
  }
  if (this._clickEvent) this._clickEvent.remove();
 }
};
// EventListener.js
const EventListener = {
 /**
  * Listen to DOM events during the bubble phase.
  *
  * @param {DOMEventTarget} target DOM element to register listener on.
  * @param {string} eventType Event type, e.g. 'click' or 'mouseover'.
  * @param {function} callback Callback function.
  * @return {object} Object with a `remove` method.
  */
 listen(target, eventType, callback) {
  if (target.addEventListener) {
   target.addEventListener(eventType, callback, false);
   return {
    remove() {
     target.removeEventListener(eventType, callback, false);
    }
   };
  } else if (target.attachEvent) {
   target.attachEvent('on' + eventType, callback);
   return {
    remove() {
     target.detachEvent('on' + eventType, callback);
    }
   };
  }
 }
};

export default EventListener;

封裝的事件監(jiān)聽(tīng)

使用

使用content屬性來(lái)決定hover時(shí)的提示信息。由placement屬性決定展示效果:placement屬性值為:方向-對(duì)齊位置;四個(gè)方向:top、left、right、bottom。trigger屬性用于設(shè)置觸發(fā)tooltip的方式,默認(rèn)為hover。

<d-tooltip content="我是tooltip">
 <d-button type="text">鼠標(biāo)移動(dòng)到我上面試試</d-button>
</d-tooltip>
<d-tooltip content="我是tooltip" trigger="click">
 <d-button type="text">點(diǎn)我試試</d-button>
</d-tooltip>

content內(nèi)容分發(fā)

設(shè)置一個(gè)名為content的slot。

<d-tooltip>
 <d-button type="text">鼠標(biāo)移動(dòng)到我上面試試</d-button>
 <p slot="content" class="tooltip-content">我是內(nèi)容分發(fā)的conent。</p>
</d-tooltip>

Attributes

參數(shù)說(shuō)明類型可選值默認(rèn)值
content顯示的內(nèi)容,也可以通過(guò) slot#content 傳入 DOMString
placementTooltip 的出現(xiàn)位置Stringtop/right/bottom/lefttop
triggertooltip觸發(fā)方式Stringhover

關(guān)于怎么在Vue中使用Tooltip組件問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

網(wǎng)頁(yè)名稱:怎么在Vue中使用Tooltip組件
標(biāo)題鏈接:http://www.aaarwkj.com/article12/ipdsdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、Google、網(wǎng)站設(shè)計(jì)公司、網(wǎng)頁(yè)設(shè)計(jì)公司、App開(kāi)發(fā)、網(wǎng)站營(yíng)銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)
国产日韩欧美亚洲一区二区| 国产日韩久久免费电影| 91蜜臀在线视频播放| 国产高清成人小视频在线| 十八禁在线观看国产一区| 日韩精品国产自拍在线| 日本av高清视频在线观看| 欧美日韩电影一区二区三区在线观看| 亚洲日本乱码一区二区三| 久久人妻蜜桃一区二区三区| 欧美人与性禽动交情品| 五月婷婷av综合激情| 黄片小视频在线免费播放| 日韩成人在线高清视频| 久久精品一区二区日韩| 99热在线播放精品观看| 久久亚洲综合精品少妇| 久久久久久国产综合精品| av在线免费观看大全| 欧美精品成人免费在线| 国产色综合一区二区| 一区二区三区欧美久久| 声入人心第一季在线观看| 白白色成人永久在线观看视频| 国产成年人免费小视频| 国产白丝诱惑在线视频| 日韩欧美人妻一二三四区| 久久久久久这里都是精品| 久久精品国产精品日韩欧美| 中文字幕在线感觉av| 日韩一二三区欧美四五区新| 丰满人妻一区二三区av| av岛国不卡一区二区在线观看| 伊人久久精品一区二区| 免费在线观看97视频| 欧美日韩国产在线91| 国产成人av在线观看| 国产在线观看一区二区三区精品| 国产不卡高清视频在线| 日本在线免费成人高清| 日韩黄av在线免费观看|