欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 使用vant插件做tabs切換和無限加載功能的實(shí)現(xiàn)

 更新時(shí)間:2020年11月04日 12:09:21   作者:李小斌96  
這篇文章主要介紹了vue 使用vant插件做tabs切換和無限加載功能的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

樣例:

1.創(chuàng)建vue項(xiàng)目,不再詳述

2.引入vant

之前用過很多插件做這個(gè)功能,但是效果都不盡人意,出現(xiàn)各種問題,直到遇到vant這個(gè)插件,完美的解決了這些小問題,如有問題,歡迎聯(lián)系我

安裝依賴

npm i vant -S

在main.js中引入

import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);

3.在頁(yè)面中使用

官方寫的比我寫的好多了,大家可以借鑒,看源代碼可能比官方給的文檔更直觀

官方文檔

我在文件中的使用,沒有使用下拉刷新的功能,大家可以直接看官網(wǎng)代碼:

<template>
 <div class="myOffice">
  <van-tabs v-model="active">
    <van-tab title="預(yù)受理">
     <van-list v-model="loading1" :finished="finished1" finished-text="沒有更多了" @load="onLoad1" :error.sync="error1" error-text="請(qǐng)求失敗,點(diǎn)擊重新加載">
      <van-cell v-for="(item,index) in list1" :key="item.PROJID" @click="handle('1',index)">
       <div class="num">{{item.PROJID}}</div>
       <div class="name">{{item.SERVICENAME}}</div>
       <div class="cleatFloat detailInfo">
        <div class="floatLeft deptName">
         <i></i>
         <span>{{item.DEPTNAME}}</span>
        </div>
        <div class="floatRight time">
         <i></i>
         <span>{{item.ACCEPTTIME.slice(0,item.ACCEPTTIME.length-2)}}</span>
        </div>
       </div>
      </van-cell>
     </van-list>
    </van-tab>
    <van-tab title="正在處理">
     <van-list v-model="loading2" :finished="finished2" finished-text="沒有更多了" @load="onLoad2" :error.sync="error2" error-text="請(qǐng)求失敗,點(diǎn)擊重新加載">
      <van-cell v-for="(item,index) in list2" :key="item.flowroleid" @click="handle('2',index)">
       <div class="num">{{item.PROJID}}</div>
       <div class="name">{{item.SERVICENAME}}</div>
       <div class="cleatFloat detailInfo">
        <div class="floatLeft deptName">
         <i></i>
         <span>{{item.DEPTNAME}}</span>
        </div>
        <div class="floatRight time">
         <i></i>
         <span>{{item.ACCEPTTIME.slice(0,item.ACCEPTTIME.length-2)}}</span>
        </div>
       </div>
      </van-cell>
     </van-list>
    </van-tab>
   </van-tabs>
 </div>
</template>
<script>
export default {
 name:'MyOffice',
 data(){
  return {
   active: 0,
   list1: [],
   loading1: false,
   finished1: false,
   error1: false,
   page1: 1,
   list2: [],
   loading2: false,
   finished2: false,
   error2: false,
   page2: 1
  }
 },
 methods:{
  onLoad1(){
   var _vm = this;
   _vm.param.pageNo = _vm.page1;
   _vm.param.handleState = '1';
   _vm.axios.post('*************',_vm.param).then(response => {
    _vm.page1 ++;
    var moreList = response.data.data.data;
    if(moreList){
     _vm.list1.push(...moreList);
     _vm.loading1 = false;
     _vm.finished1 = false;
    }else{
     _vm.loading1 = false;
     _vm.finished1 = true;
    }
   }).catch(error => {
    _vm.error1 = true;
    _vm.loading1 = false;
   })
  },
  onLoad2(){
   var _vm = this;
   _vm.param.pageNo = _vm.page2;
   _vm.param.handleState = '2';
   _vm.axios.post('******************',_vm.param).then(response => {
    _vm.page2 ++;
    var moreList = response.data.data.data;
    if(moreList){
     _vm.list2.push(...moreList);
     _vm.loading2 = false;
     _vm.finished2 = false;
    }else{
     _vm.loading2 = false;
     _vm.finished2 = true;
    }
   }).catch(error => {
    console.log(error);
    _vm.error2 = true;
    _vm.loading2 = false;
   })
  },
  handle(type,index){
   this.$router.push('/itemDetail?type=' + type + '&index=' + index);
  }
 }
}
</script>

補(bǔ)充知識(shí):Vant 在vue中 按需引入和全部加載

1. 問題描述:

在vue-cli 2.x 腳手架中練習(xí)使用vant組件庫(kù), 在main.js用于組件的時(shí)候 報(bào)錯(cuò) Vant is not defined

因?yàn)槲沂菧y(cè)試練習(xí)vant的 ; demo分為 全部加載 和按需加載兩種方式

按需加載

1.首先搭建vue腳手架,

2.下載vant

3. 下載 babel-plugin-import (按需加載使用)

3.當(dāng)下載好了以后,就可以在 .vue文件中使用了

下載vant: cnpm install vant -S

下載babel-plugin-import: cnpm install babel-plugin-import -S

首先引入: (官方文檔):

import Vue from 'vue';
import { Button } from 'vant';

Vue.use(Button);

我的寫法:

<template>
 <van-popup v-model="show" position="top" :style="{ height: '30%' }" />
  <van-cell-group>
   <van-cell title="單元格" value="內(nèi)容" />
   <van-cell title="單元格" value="內(nèi)容" label="描述信息" />
  </van-cell-group>
</template>
<script>
import { Popup } from "vant";
import { Cell, CellGroup } from "vant";

components:{
  [Cell.name]: Cell,
  [CellGroup.name]: CellGroup,
}
</script>

大家可以在計(jì)算屬性中打印一下你引入的組件,看看里面有什么了

全部加載

第一步: 下載vue腳手架

vue init webpack 項(xiàng)目名;

第二步: 下載vant

cnpm install vant -S

在main.js 中 以引入并使用

import Vant from 'vant'
import 'vant/lib/index.css'

Vue.use(Vant);

-未修改之前的 .babelrc 文件

{
 "presets": [
  ["env", {
   "modules": false,
   "targets": {
    "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
   }
  }],
  "stage-2"
 ],
 "plugins": ["transform-vue-jsx", "transform-runtime"]
}

第三步: 安裝babel-plugin-import (這部是按需加載的時(shí)候需要用到的,如果你全部引入了 就不需要)

cnpm install babel-plugin-import -S

-在 下載 babel-plugin-import 后修改 .babelrc的文件

{
 "presets": [
  ["env", {
   "modules": false,
   "targets": {
    "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
   }
  }],
  "stage-2"
 ],
 "plugins": ["transform-vue-jsx", "transform-runtime", ["import",{"libraryName":"vant","style":true}]],
 "env": {
  "test": {
   "presets": ["env", "stage-2"],
   "plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
  }
 }
}

第四.如果你安裝了babel-plugin-import 這個(gè) 然后需要把這個(gè)卸載掉, 然后重新項(xiàng)目; 在你卸載掉babel-plugin-import 這個(gè)的時(shí)候 .babelrc這個(gè)文件也要恢復(fù)到一開始沒修改的樣子偶(就是上面的''未修改之前的 .babelrc 文件)

cnpm uninstall babel-plugin-import -S

接下來重啟項(xiàng)目就應(yīng)該可以了。

以上這篇vue 使用vant插件做tabs切換和無限加載功能的實(shí)現(xiàn)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue自定義表格列的實(shí)現(xiàn)過程記錄

    vue自定義表格列的實(shí)現(xiàn)過程記錄

    這篇文章主要給大家介紹了關(guān)于vue自定義表格列的相關(guān)資料,表格組件在開發(fā)中經(jīng)常會(huì)用到,文章通過示例代碼介紹的也很詳細(xì),需要的朋友可以參考下
    2021-06-06
  • 快速理解Vue路由導(dǎo)航守衛(wèi)

    快速理解Vue路由導(dǎo)航守衛(wèi)

    這篇文章主要介紹了快速理解Vue路由導(dǎo)航守衛(wèi),“導(dǎo)航”表示路由正在發(fā)生變化,vue-router?提供的導(dǎo)航守衛(wèi)主要用來通過跳轉(zhuǎn)或取消的方式守衛(wèi)導(dǎo)航。有多種機(jī)會(huì)植入路由導(dǎo)航過程?中:全局的,?單個(gè)路由獨(dú)享的,?或者組件級(jí)的,下面來快速來接具體內(nèi)容吧
    2021-12-12
  • vue3在單個(gè)組件中實(shí)現(xiàn)類似mixin的事件調(diào)用

    vue3在單個(gè)組件中實(shí)現(xiàn)類似mixin的事件調(diào)用

    這篇文章主要為大家詳細(xì)介紹了vue3如何在單個(gè)組件中實(shí)現(xiàn)類似mixin的事件調(diào)用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • vue插件開發(fā)之使用pdf.js實(shí)現(xiàn)手機(jī)端在線預(yù)覽pdf文檔的方法

    vue插件開發(fā)之使用pdf.js實(shí)現(xiàn)手機(jī)端在線預(yù)覽pdf文檔的方法

    這篇文章主要介紹了vue插件開發(fā)之使用pdf.js實(shí)現(xiàn)手機(jī)端在線預(yù)覽pdf文檔的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-07-07
  • vue中useVModel()的使用方法(通俗易懂)

    vue中useVModel()的使用方法(通俗易懂)

    useVModel()用來實(shí)現(xiàn)父子組件間數(shù)據(jù)的雙向綁定,若不想使用默認(rèn)回調(diào),也可以自己使用emit實(shí)現(xiàn)回調(diào),這篇文章主要給大家介紹了關(guān)于vue中useVModel()使用方法的相關(guān)資料,需要的朋友可以參考下
    2024-03-03
  • vue中使用iview自定義驗(yàn)證關(guān)鍵詞輸入框問題及解決方法

    vue中使用iview自定義驗(yàn)證關(guān)鍵詞輸入框問題及解決方法

    這篇文章主要介紹了vue中使用iview自定義驗(yàn)證關(guān)鍵詞輸入框問題及解決方法,本文通過實(shí)例結(jié)合代碼的形式給大家介紹解決方法,需要的朋友可以參考下
    2018-03-03
  • vue-Split實(shí)現(xiàn)面板分割

    vue-Split實(shí)現(xiàn)面板分割

    這篇文章主要為大家詳細(xì)介紹了vue-Split實(shí)現(xiàn)面板分割,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • VUE中常用的四種高級(jí)方法總結(jié)

    VUE中常用的四種高級(jí)方法總結(jié)

    開發(fā)vue項(xiàng)目的時(shí)候一般都會(huì)開發(fā)很多自定義的全局組件,下面這篇文章主要給大家總結(jié)介紹了關(guān)于VUE中常用的四種高級(jí)方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-05-05
  • 在Vue組件上動(dòng)態(tài)添加和刪除屬性方法

    在Vue組件上動(dòng)態(tài)添加和刪除屬性方法

    下面小編就為大家分享一篇在Vue組件上動(dòng)態(tài)添加和刪除屬性方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • Vue 2.X的狀態(tài)管理vuex記錄詳解

    Vue 2.X的狀態(tài)管理vuex記錄詳解

    這篇文章主要介紹了Vue 2.X的狀態(tài)管理vuex記錄的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家的理解和學(xué)習(xí)具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。
    2017-03-03

最新評(píng)論