欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

vue怎么實現(xiàn)管理系統(tǒng)頂部tags瀏覽歷史

本文小編為大家詳細介紹“vue怎么實現(xiàn)管理系統(tǒng)頂部tags瀏覽歷史”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當,希望這篇“vue怎么實現(xiàn)管理系統(tǒng)頂部tags瀏覽歷史”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習新知識吧。

網(wǎng)站的建設(shè)創(chuàng)新互聯(lián)公司專注網(wǎng)站定制,經(jīng)驗豐富,不做模板,主營網(wǎng)站定制開發(fā).小程序定制開發(fā),H5頁面制作!給你煥然一新的設(shè)計體驗!已為火鍋店設(shè)計等企業(yè)提供專業(yè)服務(wù)。

不用任何vuex,亂七八糟的方法,全在一個文件,粘貼即用

放到你想要的位置即可(此demo,放在了面包屑上面)

先安裝 (監(jiān)聽某dom元素大小的包)

npm install element-resize-detector

tags.vue

<template>

  <div>

    <div class="tags">

      <!-- 左箭頭 -->

      <div

        class="arrow arrow_left"

        v-show="arrowVisible"

        @click="handleClickToLeft"

      >

        <i class="el-icon-arrow-left"></i>

      </div>

      <!-- 標簽內(nèi)容 -->

      <div class="tags_content" ref="box">

        <span ref="tags">

          <el-tag

            v-for="(tag, index) in tags"

            :key="tag.name"

            :class="[active == index ? 'active top_tags' : 'top_tags']"

            effect="dark"

            :closable="tag.name != 'Firstpage1'"

            @close="handleClose(index, tag)"

            @click="clickTag(index, tag)"

            @contextmenu.native.prevent="handleClickContextMenu(index, tag)"

          >

            {{ $t("router." + tag.name) }}

          </el-tag>

        </span>

      </div>

      <!-- 右箭頭 -->

      <div

        class="arrow arrow_right"

        v-show="arrowVisible"

        @click="handleClickToRight"

      >

        <i class="el-icon-arrow-right"></i>

      </div>

    </div>

    <!-- 右鍵菜單 -->

    <ul

      v-show="contextMenu.isShow"

      :style="{ left: contextMenu.menuLeft, top: '96px' }"

      class="el-dropdown-menu el-popper"

      x-placement="bottom-end"

    >

      <li

        v-if="this.active == this.contextMenu.index"

        class="el-dropdown-menu__item"

        @click="refresh"

      >

        刷新

      </li>

      <li class="el-dropdown-menu__item" @click="closeRightTag">

        關(guān)閉右側(cè)

      </li>

      <li class="el-dropdown-menu__item" @click="closeOtherTag">

        關(guān)閉其它

      </li>

      <div x-arrow="" class="popper__arrow" style="left: 44px;"></div>

    </ul>

  </div>

</template>

<script>

import elementResizeDetectorMaker from "element-resize-detector";

export default {

  data() {

    return {

      // 是否有箭頭

      arrowVisible: true,

      // 點擊次數(shù)

      num: 0,

      active: 0,

      tags: [],

      // 右鍵的元素

      contextMenu: {

        index: 0,

        tag: {},

        menuLeft: 0,

        isShow: false

      }

    };

  },

  watch: {

    $route() {

      this.getThisPage();

    },

    tags() {

      this.listenFun(this.$refs.tags, "tags");

    }

  },

  mounted() {

    this.listenFun(this.$refs.box, "box");

    var that = this;

    document.addEventListener("click", function(e) {

      that.contextMenu.isShow = false;

    });

  },

  methods: {

    // 監(jiān)聽可視區(qū)域?qū)?,瀏覽器窗口大小改變執(zhí)行

    listenFun(monitor, dom) {

      let boxWidth = this.$refs.box.offsetWidth,

        tagsWidth = this.$refs.tags.offsetWidth,

        erd = elementResizeDetectorMaker();

      erd.listenTo(monitor, ele => {

        this.$nextTick(() => {

          if (

            (dom == "box" && ele.offsetWidth >= tagsWidth) ||

            (dom == "tags" && ele.offsetWidth <= boxWidth)

          ) {

            this.arrowVisible = false;

            this.$refs.box.style.paddingLeft = "16px";

            this.$refs.box.style.paddingRight = "16px";

            this.$refs.box.style.transform = "TranslateX(0px)";

            this.num = 0;

          } else {

            this.arrowVisible = true;

            this.$refs.box.style.paddingLeft = "56px";

            this.$refs.box.style.paddingRight = "56px";

          }

        });

      });

    },

    // 判斷當前頁

    getThisPage() {

      let currentPgae = this.$route;

      // 判斷tags里是否有當前頁面

      var index = this.tags.findIndex(tag => tag.name == currentPgae.name);

      if (index == -1) {

        this.tags.push({

          name: currentPgae.name,

          path: currentPgae.path

        });

      }

      // 當前選擇頁

      this.active = this.tags.findIndex(tag => tag.name == currentPgae.name);

    },

    // 關(guān)閉標簽

    handleClose(index, tag) {

      this.tags.splice(this.tags.indexOf(tag), 1);

      if (index == this.tags.length) {

        this.active = index - 1;

        this.$router.push(this.tags[index - 1].path);

      } else {

        this.$router.push(this.tags[index].path);

      }

    },

    // 點擊標簽

    clickTag(index, tag) {

      this.active = index;

      this.$router.push(tag.path);

    },

    // 左側(cè)按鈕

    handleClickToLeft() {

      if (this.num > 0) {

        this.num--;

        this.$refs.box.style.transform = &mdash;&mdash;TranslateX(-${this.num * 200}px)&mdash;&mdash;;

      }

    },

    // 右側(cè)按鈕

    handleClickToRight() {

      // 最后一個標簽右測距離瀏覽器左側(cè)距離

      let lastChild = document

        .querySelectorAll(".top_tags")

        [this.tags.length - 1].getBoundingClientRect()。right;

      // 可視窗口的寬

      let bodyWidth = document.body.offsetWidth;

      // 右側(cè)箭頭48+右側(cè)邊距16

      if (bodyWidth - lastChild <= 64) {

        this.num++;

        this.$refs.box.style.transform = &mdash;&mdash;TranslateX(-${this.num * 200}px)&mdash;&mdash;;

      }

    },

    // 右鍵

    handleClickContextMenu(index, tag) {

      this.contextMenu.isShow = true;

      this.contextMenu.index = index;

      this.contextMenu.tag = tag;

      let isTag = document

        .querySelectorAll(".top_tags")

        [index].getBoundingClientRect();

      this.contextMenu.menuLeft = isTag.left - 48 + isTag.width / 2 + "px";

    },

    // 刷新

    refresh() {

      this.$router.go(0);

    },

    // 關(guān)閉其他

    closeOtherTag() {

      let tagsLin = this.tags.length,

        { index, tag, menuLeft } = this.contextMenu;

      if (index != 0) {

        this.tags = [

          {

            name: "Firstpage1",

            path: "/First/page1"

          },

          {

            name: tag.name,

            path: tag.path

          }

        ];

      } else {

        this.tags = [

          {

            name: "Firstpage1",

            path: "/First/page1"

          }

        ];

      }

      this.active = index;

      this.$router.push(tag.path);

    },

    // 關(guān)閉右側(cè)

    closeRightTag() {

      let tagsLin = this.tags.length,

        { index, tag, menuLeft } = this.contextMenu;

      this.tags.splice(index + 1, tagsLin - index);

      this.active = index;

      this.$router.push(tag.path);

    }

  },

  created() {

    // 監(jiān)聽頁面刷新

    window.addEventListener("beforeunload", e => {

      localStorage.setItem(

        "tagInfo",

        JSON.stringify({

          active: this.active,

          tags: this.tags

        })

      );

    });

    let tagInfo = localStorage.getItem("tagInfo")

      ? JSON.parse(localStorage.getItem("tagInfo"))

      : {

          active: 0,

          tags: [

            {

              name: "Firstpage1",

              path: "/First/page1"

            }

          ]

        };

    this.active = tagInfo.active;

    this.tags = tagInfo.tags;

  }

};

</script>

<style lang="less" scoped>

/deep/.el-tag--dark {

  border-color: transparent;

}

/deep/.el-tag--dark .el-tag__close {

  color: #86909c;

  font-size: 16px;

}

/deep/.el-tag--dark .el-tag__close:hover {

  background: #e7eaf0;

}

.tags {

  position: relative;

  overflow: hidden;

  .arrow {

    width: 48px;

    text-align: center;

    cursor: pointer;

    background: #fff;

    position: absolute;

    z-index: 1;

    &_left {

      left: 0;

      top: 0;

    }

    &_right {

      right: 0;

      top: 0;

    }

  }

  &_content {

    transition: 0.3s;

    white-space: nowrap;

    // padding: 0 16px;

  }

  .top_tags {

    margin-right: 8px;

    cursor: pointer;

    background: #fff;

    font-size: 12px;

    font-weight: 400;

    color: #1d2129;

  }

  .top_tags:hover,

  .active,

  .arrow:hover {

    background: #e7eaf0;

  }

}

</style>

重點

需要修改的地方

currentPgae.name 是路由結(jié)構(gòu)的name,判斷有無存在,沒有就添加,有就定位到上面,根據(jù)項目修改

監(jiān)聽刷新時,去本地存儲 tags 和 當前頁面的active,F(xiàn)tistpage1 改成自己的首頁即可

讀到這里,這篇“vue怎么實現(xiàn)管理系統(tǒng)頂部tags瀏覽歷史”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)站標題:vue怎么實現(xiàn)管理系統(tǒng)頂部tags瀏覽歷史
當前網(wǎng)址:http://chinadenli.net/article44/jsidhe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、軟件開發(fā)、網(wǎng)站設(shè)計公司品牌網(wǎng)站設(shè)計、面包屑導(dǎo)航、關(guān)鍵詞優(yōu)化

廣告

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

成都網(wǎng)頁設(shè)計公司
日韩欧美精品一区二区三区| 亚洲国产四季欧美一区| 在线观看国产午夜福利| 欧美日韩国产成人高潮| 日韩精品少妇人妻一区二区| 日本一区二区三区久久娇喘| 亚洲精品福利视频在线观看| 字幕日本欧美一区二区| 国产精品白丝一区二区| 色哟哟国产精品免费视频| 麻豆视传媒短视频在线看| 欧美欧美欧美欧美一区| 亚洲中文字幕乱码亚洲| 黄色激情视频中文字幕| 好骚国产99在线中文| 国产无摭挡又爽又色又刺激| 人妻久久一区二区三区精品99| 冬爱琴音一区二区中文字幕| 小草少妇视频免费看视频| 国产日本欧美特黄在线观看| 中文字幕日韩欧美理伦片| 色播五月激情五月婷婷| 男女午夜视频在线观看免费| 91麻豆视频国产一区二区| 日本成人三级在线播放| 亚洲综合一区二区三区在线| 中国一区二区三区人妻| 婷婷色网视频在线播放| 日韩精品视频一二三区| 国产永久免费高清在线精品 | 黄片在线免费观看全集 | 国产女性精品一区二区三区| 青青操成人免费在线视频| 久久综合日韩精品免费观看| 三级高清有码在线观看| 日本久久精品在线观看| 久久机热频这里只精品| 99热中文字幕在线精品| 国产精品久久男人的天堂| 精品国产一区二区欧美| 精品人妻少妇二区三区|