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

Vue在echarts?tooltip中添加點(diǎn)擊事件案例詳解

 更新時(shí)間:2021年11月23日 15:59:32   作者:靜水思流  
本文主要介紹了Vue項(xiàng)目中在echarts?tooltip添加點(diǎn)擊事件的案例詳解,代碼具有一定的價(jià)值,感興趣的小伙伴可以來學(xué)習(xí)一下

需求

需要在echarts tooltip點(diǎn)擊學(xué)校的名稱,跳轉(zhuǎn)到詳情頁面;項(xiàng)目是從上海市---> 某個(gè)區(qū)----> 具體的學(xué)校(在最后一級(jí)的tooltip中綁定一個(gè)點(diǎn)擊事件)

?項(xiàng)目是用vue和echarts實(shí)現(xiàn)的,echarts是新版本(^5.0.2),并不能把點(diǎn)擊事件綁定在window上

解決方法

1、設(shè)置tooltip

enterable: true, //允許鼠標(biāo)進(jìn)入提示懸浮層中,triggeron:'click',//提示框觸發(fā)的條件? mousemove鼠標(biāo)移動(dòng)時(shí)觸發(fā) click鼠標(biāo)點(diǎn)擊時(shí)觸發(fā)? 'mousemove|click'同時(shí)鼠標(biāo)移動(dòng)和點(diǎn)擊時(shí)觸發(fā)

tooltip: {
          // 提示框組件
          show: true, // 顯示提示框組件
          trigger: "item", // 觸發(fā)類型
          triggerOn: "mousemove", // 出發(fā)條件
          //   formatter: "名稱:<br/>坐標(biāo):{c}",
          enterable: true, //允許鼠標(biāo)進(jìn)入提示懸浮層中
          showContent: true,
          triggerOn: "click", //提示框觸發(fā)的條件  mousemove鼠標(biāo)移動(dòng)時(shí)觸發(fā) click鼠標(biāo)點(diǎn)擊時(shí)觸發(fā)  'mousemove|click'同時(shí)鼠標(biāo)移動(dòng)和點(diǎn)擊時(shí)觸發(fā)
          //   confine: true, //把toolTip限制在圖表的區(qū)域內(nèi)
          className: "areaTool",
          // hideDelay: 100000, //延時(shí)消失時(shí)間
          formatter: (item) => {
            this.hookToolTip = item;
            // 經(jīng)緯度太長需要對位數(shù)進(jìn)行截取顯示,保留七位小數(shù)
            // 需要綁定點(diǎn)擊事件
            var tipHtml = "";
            tipHtml =
              '<div style="width:2.5rem;height:80%;background:rgba(22,80,158,0.8);border:0.0125rem solid rgba(7,166,255,0.7)">' +
              '<div style="width:100%;height:0.375rem;line-height:0.375rem;border-bottom:0.025rem solid rgba(7,166,255,0.7);">' +
              '<i style="display:inline-block;width:0.125rem;height:0.125rem;background:#16d6ff;border-radius:0.5rem;">' +
              "</i>" +
              '<span id="btn-tooltip" style="margin-left:0.125rem;color:#fff;font-size:0.2rem;cursor:pointer">' +   
              item.name +
              "</span>" +
              "</div>" +
              '<div style="padding:0.1875rem;text-align: left;">' +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "經(jīng)度" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.value[0].substr(0, 11) +
              "</span>" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "緯度" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.value[1].substr(0, 11) +
              "</span>" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "考場數(shù)" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.componentIndex +
              "</span>" +
              "個(gè)" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "監(jiān)考教師" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.componentIndex +
              "</span>" +
              "個(gè)" +
              "</p>";

            return tipHtml;
          },
        },

2、定義hookToolTip變量

在formatter中給hookToolTip賦值,添加一個(gè)id,然后通過watch去檢測dom元素,可以通過onclick去綁定事件,也可以通過addEventListerner去注冊事件

watch: {
    hookToolTip: {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal, "---------watch");
        let tooltipButton = document.querySelectorAll("#btn-tooltip");
        //通過onclick注冊事件 querySelectorAll獲取的元素是一個(gè)數(shù)組
        if (tooltipButton.length > 0) {
          tooltipButton[0].onclick = this.pointNameClick;
        }
        // 通過addEventListener注冊事件
        for (let i = 0; i < tooltipButton.length; i++) {
          tooltipButton[i].addEventListener("click", this.chartClick);
        }
      },
      //   immediate: true,
      //   deep: true,
    },
  },

3、在methods中添加方法

4、完整代碼

data(){
       hookToolTip: {},     
},

  watch: {
    hookToolTip: {
      handler(newVal, oldVal) {
        console.log(newVal, oldVal, "---------watch");
        let tooltipButton = document.querySelectorAll("#btn-tooltip");
        //通過onclick注冊事件 querySelectorAll獲取的元素是一個(gè)數(shù)組
        if (tooltipButton.length > 0) {
          tooltipButton[0].onclick = this.pointNameClick;
        }
        // 通過addEventListener注冊事件
        for (let i = 0; i < tooltipButton.length; i++) {
          tooltipButton[i].addEventListener("click", this.chartClick);
        }
      },
      //并不需要進(jìn)入頁面就檢查
      //   immediate: true,
      //   deep: true,
    },
  },

  methods: {
    chartClick() {
      console.log(
        this.hookToolTip,
        "-------addEventList",
        this.hookToolTip.name
      );
    },
 },

    
//echarts
      tooltip: {
          // 提示框組件
          show: true, // 顯示提示框組件
          trigger: "item", // 觸發(fā)類型
          triggerOn: "mousemove", // 出發(fā)條件
          //   formatter: "名稱:<br/>坐標(biāo):{c}",
          enterable: true, //允許鼠標(biāo)進(jìn)入提示懸浮層中
          showContent: true,
          triggerOn: "click", //提示框觸發(fā)的條件  mousemove鼠標(biāo)移動(dòng)時(shí)觸發(fā) click鼠標(biāo)點(diǎn)擊時(shí)觸發(fā)  'mousemove|click'同時(shí)鼠標(biāo)移動(dòng)和點(diǎn)擊時(shí)觸發(fā)
          //   confine: true, //把toolTip限制在圖表的區(qū)域內(nèi)
          className: "areaTool",
          // hideDelay: 100000, //延時(shí)消失時(shí)間
          formatter: (item) => {
            this.hookToolTip = item;
            console.log(item, "-----", this.hookToolTip);
            // 經(jīng)緯度太長需要對位數(shù)進(jìn)行截取顯示,保留七位小數(shù)
            // 需要綁定點(diǎn)擊事件
            var tipHtml = "";
            tipHtml =
              '<div style="width:2.5rem;height:80%;background:rgba(22,80,158,0.8);border:0.0125rem solid rgba(7,166,255,0.7)">' +
              '<div style="width:100%;height:0.375rem;line-height:0.375rem;border-bottom:0.025rem solid rgba(7,166,255,0.7);">' +
              '<i style="display:inline-block;width:0.125rem;height:0.125rem;background:#16d6ff;border-radius:0.5rem;">' +
              "</i>" +
              '<span id="btn-tooltip" style="margin-left:0.125rem;color:#fff;font-size:0.2rem;cursor:pointer" onclick="chartClick">' +
              item.name +
              "</span>" +
              "</div>" +
              '<div style="padding:0.1875rem;text-align: left;">' +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "經(jīng)度" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.value[0].substr(0, 11) +
              "</span>" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "緯度" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.value[1].substr(0, 11) +
              "</span>" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "考場數(shù)" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.componentIndex +
              "</span>" +
              "個(gè)" +
              "</p>" +
              '<p style="color:#fff;font-size:0.15rem;">' +
              '<i style="display:inline-block;width:0.1rem;height:0.1rem;background:#16d6ff;border-radius:0.5rem;margin:0 0.1rem">' +
              "</i>" +
              "監(jiān)考教師" +
              '<span style="color:#11ee7d;margin:0 0.075rem;">' +
              item.componentIndex +
              "</span>" +
              "個(gè)" +
              "</p>";

            return tipHtml;
          },
        },

到此這篇關(guān)于Vue在echarts tooltip中添加點(diǎn)擊事件案例詳解的文章就介紹到這了,更多相關(guān)Vue的內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 一文詳解Vue中如何實(shí)現(xiàn)頁面骨架屏

    一文詳解Vue中如何實(shí)現(xiàn)頁面骨架屏

    為了提升頁面加載速度,我們可以使用頁面骨架屏技術(shù)來優(yōu)化用戶感知,下面就跟隨小編一起學(xué)習(xí)一下如何在vue中實(shí)現(xiàn)頁面骨架屏吧
    2024-03-03
  • Vue.js高效前端開發(fā)

    Vue.js高效前端開發(fā)

    Vue是構(gòu)建Web界面的JavaScript庫,原稱為Vue.js,它可以通過簡潔的API來提供高效的數(shù)據(jù)綁定和靈活的組件系統(tǒng),本文詳細(xì)介紹了Vue的使用安裝和相關(guān)知識(shí),有興趣的同學(xué)可以參考借鑒
    2023-03-03
  • vue 左滑刪除功能的示例代碼

    vue 左滑刪除功能的示例代碼

    這篇文章主要介紹了vue 左滑刪除功能的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • 在Vue methods中調(diào)用filters里的過濾器實(shí)例

    在Vue methods中調(diào)用filters里的過濾器實(shí)例

    今天小編就為大家分享一篇在Vue methods中調(diào)用filters里的過濾器實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Vite創(chuàng)建Vue3項(xiàng)目及Vue3使用jsx詳解

    Vite創(chuàng)建Vue3項(xiàng)目及Vue3使用jsx詳解

    vite是新一代的前端構(gòu)建工具,下面這篇文章主要給大家介紹了關(guān)于Vite創(chuàng)建Vue3項(xiàng)目以及Vue3使用jsx的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • element el-table如何實(shí)現(xiàn)表格動(dòng)態(tài)增加/刪除/編輯表格行(帶校驗(yàn)規(guī)則)

    element el-table如何實(shí)現(xiàn)表格動(dòng)態(tài)增加/刪除/編輯表格行(帶校驗(yàn)規(guī)則)

    這篇文章主要介紹了element el-table如何實(shí)現(xiàn)表格動(dòng)態(tài)增加/刪除/編輯表格行(帶校驗(yàn)規(guī)則),本篇文章記錄el-table增加一行可編輯的數(shù)據(jù)列,進(jìn)行增刪改,感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • 解決VuePress頁面亂碼問題

    解決VuePress頁面亂碼問題

    這篇文章主要介紹了解決VuePress頁面亂碼問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 基于vue3+TypeScript實(shí)現(xiàn)一個(gè)簡易的Calendar組件

    基于vue3+TypeScript實(shí)現(xiàn)一個(gè)簡易的Calendar組件

    最近在學(xué)習(xí) react,在學(xué)習(xí)到使用 react 開發(fā) Calendar 組件的時(shí)候,突然聯(lián)想到使用 vue 進(jìn)行 Calendar 功能的實(shí)現(xiàn),因?yàn)槟壳笆褂玫募夹g(shù)棧是 vue,剛好可以加深下對 vue3 和 ts 的使用印象,所以本文給大家介紹了基于vue3+TypeScript實(shí)現(xiàn)一個(gè)簡易的Calendar組件
    2024-05-05
  • 利用vue實(shí)現(xiàn)模態(tài)框組件

    利用vue實(shí)現(xiàn)模態(tài)框組件

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)模態(tài)框組件的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Vue3使用富文本框(wangeditor)的方法總結(jié)

    Vue3使用富文本框(wangeditor)的方法總結(jié)

    項(xiàng)目中用到了富文本,選來選去選擇了wangeditor,下面這篇文章主要給大家介紹了關(guān)于Vue3使用富文本框(wangeditor)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-01-01

最新評(píng)論

郓城县| 蒲城县| 马山县| 太谷县| 开封县| 遂溪县| 固安县| 临沭县| 巴南区| 甘肃省| 田东县| 台北县| 新营市| 藁城市| 嘉荫县| 贵德县| 乐东| 苏尼特右旗| 桂阳县| 萨嘎县| 师宗县| 长阳| 竹北市| 贺州市| 安福县| 永春县| 缙云县| 辽宁省| 旺苍县| 伊春市| 百色市| 苍山县| 文安县| 新泰市| 吕梁市| 文昌市| 和硕县| 响水县| 延边| 繁昌县| 丹棱县|