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

vue自定義穿梭框支持遠(yuǎn)程滾動(dòng)加載的實(shí)現(xiàn)方法

 更新時(shí)間:2023年08月16日 09:03:42   作者:SunnyRun!  
這篇文章主要介紹了vue自定義穿梭框支持遠(yuǎn)程滾動(dòng)加載,iview是全局注入,基本使用原先的類名進(jìn)行二次創(chuàng)建公共組件,修改基礎(chǔ)js實(shí)現(xiàn)邏輯,本文結(jié)合實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下

*分享一個(gè)使用比較久的??

技術(shù)框架公司的選型(老項(xiàng)目):vue2 + iview-ui方案的實(shí)現(xiàn)思路是共性的,展現(xiàn)UI樣式需要你們自定義進(jìn)行更改;因?yàn)閕view是全局注入,基本使用原先的類名進(jìn)行二次創(chuàng)建公共組件,修改基礎(chǔ)js實(shí)現(xiàn)邏輯;

需求分析:實(shí)現(xiàn)遠(yuǎn)程滾動(dòng)加載數(shù)據(jù)的穿梭框
1、創(chuàng)建自定義穿梭框,分左側(cè)和右側(cè)數(shù)據(jù)
2、依賴后端接口,左側(cè)是左側(cè)數(shù)據(jù),右側(cè)是右側(cè)數(shù)據(jù)
3、定義好出入?yún)?shù),支持回顯內(nèi)容及選中內(nèi)容的去重處理
4、綁定對(duì)應(yīng)的v-model數(shù)據(jù)響應(yīng)
5、滾動(dòng)加載數(shù)據(jù),區(qū)分左右區(qū)域;添加自定義指令進(jìn)行監(jiān)聽
6、滾動(dòng)加載數(shù)據(jù),不丟失已選中的數(shù)據(jù),或去重已選中數(shù)據(jù)
7、支持左右側(cè)的遠(yuǎn)程搜索功能,左右互不影響,檢索數(shù)據(jù)放組件外部進(jìn)行

在這里插入圖片描述

1、代碼信息

創(chuàng)建ivu-transfer.vue文件;依賴iviewUI請(qǐng)依據(jù)自己的樣式進(jìn)行拷貝;

1.1 自定義滾動(dòng)監(jiān)聽指令

/** 遠(yuǎn)程滾動(dòng)加載 */
import Vue from 'vue'
Vue.directive("loadTransfer", {
  bind(el, binding) {
    const select_dom = el.querySelectorAll('.ivu-transfer-list .ivu-transfer-list-content');
    select_dom.forEach((item, index) => {
      item.addEventListener('scroll', function () {
        const height = this.scrollHeight - this.scrollTop - 1 <= this.clientHeight;
        if (height) {
          binding.value(index)
        }
      })
    })
  }
})

1.2 自定義穿梭框代碼

<template>
  <div class="ivu-transfer">
    <div
      class="ivu-transfer-list"
      :style="{
        width: listStyle.width,
        height: listStyle.height
      }"
    >
      <div class="ivu-transfer-list-header">
        <Checkbox
          :value="checkLeftAll"
          @on-change="handleAllLeftCheck"
        ></Checkbox>
        <span class="ivu-transfer-list-header-title">源列表</span>
        <span class="ivu-transfer-list-header-count">
          {{ leftDataSource.length }}
        </span>
      </div>
      <div class="ivu-transfer-list-body">
        <div class="ivu-transfer-list-content">
          <CheckboxGroup v-model="checkLeftAllGroup">
            <Checkbox
              :key="index"
              :label="item.value"
              class="ivu-transfer-list-content-item"
              v-for="(item, index) in leftDataSource"
              >{{
                item.label +
                  `${item.description ? ` - ${item.description}` : ""}`
              }}</Checkbox
            >
          </CheckboxGroup>
          <div
            v-if="!leftDataSource.length"
            class="ivu-transfer-list-content-not-found"
          >
            列表為空
          </div>
        </div>
      </div>
    </div>
    <div class="ivu-transfer-operation">
      <Button
        size="small"
        type="primary"
        icon="ios-arrow-back"
        @click="handleClickArrowBack"
        :disabled="!checkRightAllGroup.length"
      ></Button>
      <Button
        size="small"
        type="primary"
        icon="ios-arrow-forward"
        @click="handleClickArrowForward"
        :disabled="!checkLeftAllGroup.length"
      ></Button>
    </div>
    <div
      class="ivu-transfer-list"
      :style="{
        width: listStyle.width,
        height: listStyle.height
      }"
    >
      <div class="ivu-transfer-list-header">
        <Checkbox
          :value="checkRightAll"
          @on-change="handleAllRightCheck"
        ></Checkbox>
        <span class="ivu-transfer-list-header-title">目的列表</span>
        <span class="ivu-transfer-list-header-count">
          {{ rightDataSource.length }}
        </span>
      </div>
      <div class="ivu-transfer-list-body">
        <div class="ivu-transfer-list-content">
          <CheckboxGroup v-model="checkRightAllGroup">
            <Checkbox
              :key="index"
              :label="item.value"
              class="ivu-transfer-list-content-item"
              v-for="(item, index) in rightDataSource"
              >{{
                item.label +
                  `${item.description ? ` - ${item.description}` : ""}`
              }}
            </Checkbox>
          </CheckboxGroup>
          <div
            v-if="!rightDataSource.length"
            class="ivu-transfer-list-content-not-found"
          >
            列表為空
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
const methods = {
  // 點(diǎn)擊左側(cè)全選
  handleAllLeftCheck() {
    this.checkLeftAll = !this.checkLeftAll;
    if (this.checkLeftAll) {
      this.checkLeftAllGroup = this.leftDataSource.map(item => item.value);
    } else {
      this.checkLeftAllGroup = [];
    }
  },
  // 點(diǎn)擊右側(cè)全選
  handleAllRightCheck() {
    this.checkRightAll = !this.checkRightAll;
    if (this.checkRightAll) {
      this.checkRightAllGroup = this.rightDataSource.map(item => item.value);
    } else {
      this.checkRightAllGroup = [];
    }
  },
  // 點(diǎn)擊向右數(shù)據(jù)
  handleClickArrowBack() {
    this.moveCheckedData("left");
  },
  // 點(diǎn)擊向左數(shù)據(jù)
  handleClickArrowForward() {
    this.moveCheckedData("right");
  },
  moveCheckedData(direction) {
    const newLeftDataSource = [];
    const newRightDataSource = [];
    const dataSource =
      direction === "left" ? this.rightDataSource : this.leftDataSource;
    dataSource.forEach(item => {
      const index =
        direction === "left"
          ? this.checkRightAllGroup.indexOf(item.value)
          : this.checkLeftAllGroup.indexOf(item.value);
      if (index !== -1) {
        direction === "left"
          ? newLeftDataSource.push(item)
          : newRightDataSource.push(item);
      } else {
        direction === "left"
          ? newRightDataSource.push(item)
          : newLeftDataSource.push(item);
      }
    });
    this.leftDataSource =
      direction === "left"
        ? [...this.leftDataSource, ...newLeftDataSource]
        : newLeftDataSource;
    this.rightDataSource =
      direction === "left"
        ? newRightDataSource
        : [...this.rightDataSource, ...newRightDataSource];
    this.checkLeftAll = false;
    this.checkRightAll = false;
    this.checkLeftAllGroup = [];
    this.checkRightAllGroup = [];
    this.$emit("on-change", this.leftDataSource, this.rightDataSource, direction);
  },
  filterDataMethods() {
    const rightValues = new Set(this.rightDataSource.map(opt => opt.value));
    this.leftDataSource = this.leftDataSource.filter(
      item => !rightValues.has(item.value)
    );
    this.$nextTick(() => {
      const leftValues = new Set(this.leftDataSource.map(opt => opt.value));
      this.rightDataSource = this.rightDataSource.filter(
        opt => !leftValues.has(opt.value)
      );
    });
  }
};
export default {
  props: {
    listStyle: {
      type: Object,
      default: () => ({
        width: "250px",
        height: "380px"
      })
    },
    leftData: {
      type: Array,
      require: true,
      default: () => []
    },
    rightData: {
      type: Array,
      require: true,
      default: () => []
    }
  },
  data() {
    return {
      checkLeftAll: false,
      checkRightAll: false,
      checkRightAllGroup: [],
      checkLeftAllGroup: [],
      leftDataSource: [],
      rightDataSource: []
    };
  },
  watch: {
    leftData(newVal) {
      this.leftDataSource = newVal;
      this.filterDataMethods();
    },
    rightData(newVal) {
      this.rightDataSource = newVal || [];
      this.filterDataMethods();
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$emit("on-change", this.leftDataSource, this.rightDataSource);
    })
  },
  methods
};
</script>
<style lang="less" scoped>
.ivu-transfer-list-content-item {
  width: 100%;
  margin-left: -0.3em;
}
.ivu-transfer-list-content-not-found {
  display: block;
}
</style>

2、內(nèi)容使用api介紹

1、樹形結(jié)構(gòu)入?yún)ⅲ篸ataSource=[{label: '測(cè)試',value: 1, description: '拼接內(nèi)容' }],
2、標(biāo)簽引用:<IvuTransfer :leftData="dataSource" :rightData="targetKeys" @on-change="handleChange" v-loadTransfer="handleLoadMore" />
3、相關(guān)api說明文檔在文章底部

<template>
 <div class="customSearch">
    <Input
      search
      clearable
      v-model="formLeftInput"
      placeholder="請(qǐng)輸入搜索內(nèi)容"
      @on-clear="handleOnLeftInput"
      @on-search="handleOnLeftInput"
    />
    <div style="width: 50px"></div>
    <Input
      search
      clearable
      v-model="formRightInput"
      placeholder="請(qǐng)輸入搜索內(nèi)容"
      @on-clear="handleOnRightInput"
      @on-search="handleOnRightInput"
    />
    </div>
    <IvuTransfer
      :leftData="dataSource"
      :rightData="targetKeys"
      @on-change="handleChange"
      v-loadTransfer="handleLoadMore"
    />
 </template>
// 遠(yuǎn)程滾動(dòng)加載
  handleLoadMore(index) {
    if (index === 0 && this.dataLeftHasMore && !this.isShowLoading) {
      this.curLeftPage++;
      this.getLeftMockData();
    }
    if (index === 1 && this.dataRightHasMore && !this.rightLoading) {
      this.curRightPage++;
      this.getRightTargetKeys();
    }
  },
  // 觸發(fā)選中移動(dòng)
  handleChange(newLeftTargetData, newRightTargetKeys, direction) {
    this.dataSource = [...newLeftTargetData];
    this.targetKeys = [...newRightTargetKeys];
    if (direction === "right") {
      return this.remoteCheckPage();
    }
    if (direction === "left") {
      return this.remoteRightCheckPage();
    }
  },
getLeftData() {},
getRightData() {}
參數(shù)說明類型默認(rèn)值必填項(xiàng)
leftData[{}]-label,value結(jié)構(gòu)Array[][]
rightData[{}]-label,value結(jié)構(gòu)Array[][]
on-change數(shù)據(jù)變更觸發(fā)newLeft,newRight, direction

到此這篇關(guān)于vue自定義穿梭框支持遠(yuǎn)程滾動(dòng)加載的文章就介紹到這了,更多相關(guān)vue遠(yuǎn)程滾動(dòng)加載內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue項(xiàng)目?jī)煞N方式實(shí)現(xiàn)豎向表格的思路分析

    vue項(xiàng)目?jī)煞N方式實(shí)現(xiàn)豎向表格的思路分析

    這篇文章主要介紹了vue項(xiàng)目?jī)煞N方式實(shí)現(xiàn)豎向表格的思路分析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Vue3狀態(tài)管理之Pinia的入門使用教程

    Vue3狀態(tài)管理之Pinia的入門使用教程

    Pinia是Vue.js的輕量級(jí)狀態(tài)管理庫(kù),比起vue3中的Vuex狀態(tài)管理,pinia更輕量,更容易使用,下面這篇文章主要給大家介紹了關(guān)于Vue3狀態(tài)管理之Pinia的入門使用教程,需要的朋友可以參考下
    2022-04-04
  • vue中的$含義及其用法詳解($xxx引用的位置)

    vue中的$含義及其用法詳解($xxx引用的位置)

    $是在vue中所有實(shí)例中都可用的一個(gè)簡(jiǎn)單約定,這樣做會(huì)避免和已被定義的數(shù)據(jù),方法,計(jì)算屬性產(chǎn)生沖突,下面這篇文章主要給大家介紹了關(guān)于vue中$含義及其用法的相關(guān)資料,需要的朋友可以參考下
    2023-04-04
  • vue如何動(dòng)態(tài)配置ip與端口

    vue如何動(dòng)態(tài)配置ip與端口

    這篇文章主要介紹了vue如何動(dòng)態(tài)配置ip與端口,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue中跨頁(yè)面通信的8種主流方式詳解

    Vue中跨頁(yè)面通信的8種主流方式詳解

    在Vue項(xiàng)目開發(fā)中,跨頁(yè)面通信是高頻需求,本文整理8種主流通信方式,每種方式附完整可運(yùn)行Demo、適配場(chǎng)景和注意事項(xiàng),覆蓋Vue2、Vue3所有項(xiàng)目場(chǎng)景,新手也能直接復(fù)制落地,快跟隨小編一起學(xué)習(xí)一下吧
    2026-04-04
  • Vue.Draggable使用文檔超詳細(xì)總結(jié)

    Vue.Draggable使用文檔超詳細(xì)總結(jié)

    Vue拖拽組件(Draggable)是一個(gè)允許與View-Model同步進(jìn)行拖放排序的Vue組件,下面這篇文章主要給大家介紹了關(guān)于Vue.Draggable使用文檔的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • vue頁(yè)面使用阿里oss上傳功能的實(shí)例(二)

    vue頁(yè)面使用阿里oss上傳功能的實(shí)例(二)

    本篇文章主要介紹了vue頁(yè)面使用阿里oss上傳功能的實(shí)例(二),主要介紹OSS管理控制臺(tái)設(shè)置訪問權(quán)限、角色等,有興趣的可以了解一下
    2017-08-08
  • 在Vue項(xiàng)目中引入JQuery-ui插件的講解

    在Vue項(xiàng)目中引入JQuery-ui插件的講解

    今天小編就為大家分享一篇關(guān)于在Vue項(xiàng)目中引入JQuery-ui插件的講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • vue全局?jǐn)?shù)據(jù)管理示例詳解

    vue全局?jǐn)?shù)據(jù)管理示例詳解

    這篇文章主要為大家介紹了vue全局?jǐn)?shù)據(jù)管理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • vue.config.js常用配置詳解

    vue.config.js常用配置詳解

    這篇文章主要介紹了vue.config.js常用配置詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評(píng)論

阜城县| 库尔勒市| 焉耆| 宁夏| 临朐县| 涟水县| 灌南县| 汉源县| 连山| 武安市| 安康市| 苍溪县| 十堰市| 拜泉县| 西宁市| 浠水县| 鄢陵县| 通山县| 卢龙县| 大邑县| 吴江市| 华阴市| 民权县| 沅陵县| 广昌县| 新源县| 广南县| 凉城县| 电白县| 宜兴市| 盐亭县| 阿拉尔市| 钟祥市| 融水| 兰西县| 乐昌市| 梓潼县| 丹凤县| 军事| 长葛市| 长寿区|