最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue組件之Tooltip的示例代碼

 更新時(shí)間:2017年10月18日 11:05:15   作者:答案在風(fēng)中飄著  
這篇文章主要介紹了Vue組件之Tooltip的示例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

前言

本文主要Alert 組件的大致框架, 提供少量可配置選項(xiàng)。 旨在大致提供思路

tooltip

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

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

<template>
 <div style="position:relative;">
  <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)聽的事件
  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)聽對(duì)象
  const triger = this.$refs.trigger.children[0];
  // 根據(jù)trigger監(jiān)聽特定事件
  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)聽,釋放內(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)聽

使用

使用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 傳入 DOM String
placement Tooltip 的出現(xiàn)位置 String top/right/bottom/left top
trigger tooltip觸發(fā)方式 String hover

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue實(shí)現(xiàn)表單驗(yàn)證功能

    vue實(shí)現(xiàn)表單驗(yàn)證功能

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)表單驗(yàn)證功能,基于NUXT的validate方法實(shí)現(xiàn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue.use源碼分析

    Vue.use源碼分析

    這篇文章主要為大家詳細(xì)介紹了Vue.use源碼,Vue.use方法的引入,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • 解決vant中 tab欄遇到的坑 van-tabs

    解決vant中 tab欄遇到的坑 van-tabs

    這篇文章主要介紹了解決vant中 tab欄遇到的坑 van-tabs,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • vue3中refs用法舉例小結(jié)

    vue3中refs用法舉例小結(jié)

    這篇文章主要給大家介紹了關(guān)于vue3中refs用法舉例的相關(guān)資料,Vue.js中的$refs是一個(gè)對(duì)象,它持有已注冊(cè)過(guò)ref特性的所有組件和元素,需要的朋友可以參考下
    2023-08-08
  • Vue動(dòng)態(tài)設(shè)置el-table操作列的寬度自適應(yīng)

    Vue動(dòng)態(tài)設(shè)置el-table操作列的寬度自適應(yīng)

    這篇文章主要給大家介紹了關(guān)于Vue如何動(dòng)態(tài)設(shè)置el-table操作列的寬度自適應(yīng),很多頁(yè)面都需要用到表格組件el-table,如果沒(méi)有給el-table-column指定寬度,默認(rèn)情況下會(huì)平均分配給剩余的列,需要的朋友可以參考下
    2023-07-07
  • npm如何更新VUE package.json文件中依賴的包版本

    npm如何更新VUE package.json文件中依賴的包版本

    這篇文章主要介紹了npm如何更新VUE package.json文件中依賴的包版本問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Vue 3中toRaw和markRaw的使用教程

    Vue 3中toRaw和markRaw的使用教程

    toRaw和markRaw是Vue 3中引入的新API,用于更精細(xì)地控制對(duì)象的代理和響應(yīng)性,它們提供了在需要時(shí)繞過(guò)代理或禁用響應(yīng)性的能力,有助于提高性能和更好地與第三方庫(kù)進(jìn)行集成,本文給大家介紹Vue 3中toRaw和markRaw的使用,感興趣的朋友一起看看吧
    2023-10-10
  • vue+axios實(shí)現(xiàn)登錄攔截的實(shí)例代碼

    vue+axios實(shí)現(xiàn)登錄攔截的實(shí)例代碼

    本篇文章主要介紹了vue+axios實(shí)現(xiàn)登錄攔截的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • Vue+ElementUI踩坑之動(dòng)態(tài)顯示/隱藏表格的列el-table-column問(wèn)題

    Vue+ElementUI踩坑之動(dòng)態(tài)顯示/隱藏表格的列el-table-column問(wèn)題

    這篇文章主要介紹了Vue+ElementUI踩坑之動(dòng)態(tài)顯示/隱藏表格的列el-table-column問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Vue中對(duì)拿到的數(shù)據(jù)進(jìn)行A-Z排序的實(shí)例

    Vue中對(duì)拿到的數(shù)據(jù)進(jìn)行A-Z排序的實(shí)例

    今天小編就為大家分享一篇Vue中對(duì)拿到的數(shù)據(jù)進(jìn)行A-Z排序的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09

最新評(píng)論

江门市| 广州市| 隆尧县| 太湖县| 得荣县| 渭源县| 新民市| 资阳市| 营口市| 卓尼县| 兴仁县| 阆中市| 永善县| 渝中区| 视频| 高密市| 漳州市| 吐鲁番市| 沙坪坝区| 益阳市| 长寿区| 汝阳县| 阜宁县| 大兴区| 东港市| 莎车县| 丰台区| 临城县| 庆城县| 恩平市| 七台河市| 靖西县| 庄浪县| 手游| 化隆| 亚东县| 获嘉县| 彰化市| 察隅县| 芜湖县| 井研县|