關於Vue+iview的簡單下拉框滾動加載

話很少說,直接上代碼,做用是下拉框內容無限滾動加載:web

Html:this

  

<FormItem style="position:relative" label="用戶名:" prop="userName">
      <Input v-model="formValidate.userName" :disabled="useNameDisable" placeholder="請輸入用戶名" @on-blur="clickblur"  @on-focus="clickFocus"></Input>
      <div class="scollClass" v-if="scollshow">
         <Scroll height="120" :on-reach-bottom="handleReachBottom">
            <div  v-for="item in userNameList" :key="item.name" @mousedown="scollListClick(item)" class="scollListClass">
                {{ item.name }}
            </div>
         </Scroll>
      </div>
</FormItem>

 

Js:
  
  
  // 無限加載中的事件
    scollListClick(val){
      this.scollshow = false;
      this.formValidate = val;
      this.Formdata = val;
      this.formValidate.userName = val.name;
      // console.log(111)
      this.handleSelectAll(false);
    },
    clickFocus(){
      this.scollshow = true;
    },
    clickblur(){
       this.scollshow = false;
    },
    // 無限加載
    handleReachBottom () {
      return new Promise(resolve => {
          this.userpage = this.userpage*1 + 1;
          setTimeout(() => {
              this.$store.dispatch('getUserNameList',{
                page:this.userpage,
                size:'5'
              } ).then(res => {
                  if (res.data.code === 200 ) {
                      if(res.data.data.list.length > 0){
                        for(let i =0;i<res.data.data.list.length;i++){
                          this.userNameList.push(res.data.data.list[i])
                        }
                      }
                  } else {
                      // util.showMsg(this, {diy:'操做失敗!'})
                  }
              })
              resolve();
          }, 500);
      });
    },

Css:spa

  

.scollClass{
  position:absolute;
  background:white;
  z-index:3;
  width:100%;
  overflow:hidden;
  border:1px solid #dddee1;
  border-radius: 4px;
  top:35px;
  ::-webkit-scrollbar
    {
      width: 6px;
      height: 16px;
      background-color: #F5F5F5;
    }
    
    /*定義滾動條軌道 內陰影+圓角*/
    ::-webkit-scrollbar-track
    {
        // -webkit-box-shadow: inset 0 0 6px #e9eaec;
        border-radius: 3px;
        background-color: #f5f7f9;
    }
    
    /*定義滑塊 內陰影+圓角*/
    ::-webkit-scrollbar-thumb
    {
      border-radius: 3px;
      // -webkit-box-shadow: inset 0 0 6px #e9e9e9;
      background-color: #ccc;
    }
}
.scollListClass{
  height:24px;
  line-height:24px;
  // font-size:16px;
  margin-left:8px;
}

 

樣式根據具體狀況能夠自行改動,進行進一步簡單完善封裝能夠直接用code

相關文章
相關標籤/搜索