vue重新整理和tab切換執行個體,vuetab執行個體

來源:互聯網
上載者:User

vue重新整理和tab切換執行個體,vuetab執行個體

首先寫個子組件用來放重新整理的內容,命名為pull(可以看例子最後面放的。)

然後再要重新整理的頁面引用

<template>   <div class="fbjbox container">   <div class="fbjbox1">  <tab ref='tab' :list="['推薦','熱門','最新']" width="33%" @change='tabchange' style="float:left"/> <span class="price" width="33%" @tap="change" >價格<span class="mui-icon mui-icon-arrowright"></span></span> //點擊價格會排序   </div>  <div class="fbjbox2">      <pull up="true" down="true" @up="next" @down="shuaxin" ref="pull">       <div class="mui-row mui-col-xs-12 mui-clearfix">      <span class="mui-col-xs-6" v-href="{name:'商品詳情'}" rel="external nofollow" v-for="item in list">       <div class="img"><img v-bind:src="item.goods_image"/></div>       <h4>{{item.goods_name}}</h4>       <p class="red1">¥{{item.goods_price}}</p>      </span>     </div>      </pull>    </div></div></template><style> /*選項卡的顏色*/ .tab{background:#fff;} .tab a.active{color:#D83737; border-bottom: 2px solid #D83737;}  .red1{color:red;font-size:15px;padding-left:10px} h4{font-size:16px;font-weight:normal;color:#656565;padding-left:10px}</style><style scoped> .container{font-family: "微軟雅黑";} .mui-row{ overflow: hidden;margin-bottom: 20px;} .mui-row .mui-col-xs-6{width:49%;background-color:#fff;overflow: hidden;margin-top:6px;text-align: left;} .mui-row .mui-col-xs-6:nth-child(even){margin-left:2%;} .mui-row img{width:100%;} .mui-row .img{height:170px;}</style><script>import tab from '../tab'import pull from '../public/pull' export default {   created() {   this.height = window.innerWidth * 40 / 64;   this.is_zc = this.$route.query.is_zc == 1;   this.uid = localStorage.getItem('uid');       },  mounted(){    this.shuaxin(() => { });    },  data() {    return {    tab:0,    list:[],   order:1 //order是排序。1的預設的,2從低到高,3從高到低   }  },  components: {tab,pull},  computed:{  //cmd也是一個變數 ,而且根據選項卡的不同而不同    cmd:function(){    switch(this.tab){     case 0: return "Mp/goodsTuijian";     case 1: return "Mp/hotGoods";     case 2: return "Mp/newGoods";    }       }  },  methods: {   tabchange({index, data}) {    this.tab = index;    },  shuaxin(done) { //首先進去以後的初始    this.$api(this.cmd, { page: 0,order:this.sort }).then(list => { //除了把頁面傳過去還需要把排序的方式傳過去      this.list=list;     done(); //跳到一個新的選項卡時,頁面從新從第一個.不是拉到的那個位置   if(this.$refs.pull){      this.$refs.pull.reset();      this.$refs.pull.nodata = false;      }    });   },  next(done) {    var page = this.list.length;    this.$api(this.cmd, { page,order:this.sort }).then(list => {     if (list.length == 0) { return done&&done(true);}  //這個裡面如果只出現done(true)的話可能就是只顯示沒有資料了,不會出現正在載入中     this.list = this.list.concat(list);     done();    });   },  change(){ //點擊價格時變化的class    if(this.sort==1){this.sort=2;}    else    if(this.sort==2){this.sort=3;}    else    if(this.sort==3){this.sort=1;}    this.shuaxin(() => { });   }     },  watch:{   //監聽。當選項卡改變的時候,重新整理頁面。   tab:function(){    this.shuaxin(() => { });       },     } }</script>

下面是命名為pull的子組件。

<template> <div class="mui-scroll-wrapper" ref="box" v-bind:style="{top:top+'px'}">  <div class="mui-pull-top-pocket mui-block" v-bind:class="{'mui-visibility':obj.y>0}" v-if="down">   <div class="mui-pull" v-show="flag">    <div class="mui-pull-loading mui-icon" v-bind:class="{'mui-spinner': type==2,'mui-icon-pulldown':type!=2}" v-bind:style="css1"></div>    <div class="mui-pull-caption" v-if="type==0">下拉可以重新整理</div>    <div class="mui-pull-caption" v-if="type==1">釋放立即重新整理</div>    <div class="mui-pull-caption" v-if="type==2">正在重新整理</div>   </div>  </div>  <div class="mui-scroll" @scrollstart.self="scrollstart" @scroll.self="scroll" @scrollbottom="scrollbottom">   <slot>    <div class="no-content">     <i></i>     <h4>暫無內容</h4>    </div>   </slot>   <div class="mui-pull-bottom-pocket mui-block mui-visibility" v-if="type==4">    <div class="mui-pull">     <div class="mui-icon mui-spinner mui-visibility" style="transition: -webkit-transform 0.3s ease-in; transform: rotate(180deg); animation: spinner-spin 1s step-end infinite;position: relative;top: 8px;"></div><div class="mui-pull-caption mui-visibility">正在載入...</div></div></div><!--<div v-if="nodata" class="nodata">已經沒有更多資料</div>--><div v-if="nodata" class="yqxtsdkn"></div></div></div></template><style scoped> .mui-scroll-wrapper { position:relative;height:100%;} .nodata { color:#efefef;text-align:center;margin-top:10px;line-height: 30px; font-size: 12px; background:#0B2E4C}</style><script> export default {  mounted() {   var box = this.$refs.box;   this.obj = mui(box).scroll();  },  props: ["down", "up", "top"],  data() {   return {    flag: false,    Y: 0,    obj: {},    type: 0,    nodata: false   }  },  computed: {   css1() {    return {     transition: this.type > 0 ? '-webkit-transform 0.3s ease-in' : "",     transform: this.type > 0 ? 'rotate(180deg)' : "",     animation: this.type == 2 ? "spinner-spin 1s step-end infinite" : ""    };   }  },  watch: {   type(a, b) {    if (b == 1) {     this.type = 2;    }    if (a == 2) {     this.flag = false;     this.obj.setTranslate(0, 50);     this.$emit("down", () => {      this.type = 0;      this.obj.setTranslate(0, 0);      this.obj.reLayout();      this.nodata = false;     });    }   }  },  methods: {  reset(){    this.obj.setTranslate(0, 0);   },   scrollstart() {    if (this.obj.lastY <= 0) {     this.flag = true;    } else {     this.Y = 0;     this.flag = false;    }   },   scroll() {    if (this.down && this.flag) {     this.type = this.obj.y > 50 ? 1 : 0;     if (this.obj.y > 0) {      this.Y = this.obj.y;     }    }   },   scrollbottom() {    if (this.nodata || !this.up || this.type == 4) return;    this.type = 4;    this.$emit("up", (n) => {     this.type = 0;     if (n == true) this.nodata = true;     this.obj.reLayout();    });   }  } }</script>

tab的一個例子

<template> <div class="mypage">    <div class="fbjbox">    <div class="fbjbox1">    <tab ref="tab" :list="['一級合伙人'+count,'二級合伙人']" width="50%" @change="tabchange" />   </div>   <div class="fbjbox2">    <template v-if="list!=null&&tab==0">      <h4 >一級合伙人總數{{count}}人</h4>      <ul class="mui-table-view clear">       <li class="mui-table-view-cell mui-media" v-for="item in list">        <img class="mui-media-object mui-pull-left circle" v-bind:src="item.head_url" />         <div class="mui-media-body">          {{item.vname}}          <p class='mui-ellipsis'>{{item.identity}}</p>         </div>       </li>            </ul>          </template>    <template v-if="list!=null&&tab==1">          <h4 >二級合伙人總數{{count}}人</h4>      <ul class="mui-table-view clear">       <li class="mui-table-view-cell mui-media" v-for="item,index in list">         <div class="mui-media-body" v-cloak>          {{type(index)}}人數<p class="mui-pull-right">{{item}}</p>         </div>       </li>             </ul>     </template>    <!--<template v-if="list==null">     <div class=" mui-text-center" style="padding: 50px;">           <span class="mui-spinner"></span>     </div>    </template>-->    <template v-if="list==[]">     <div>暫無下線</div>    </template>   </div>  </div>  </div></template><style scoped="">p{color:#807E7E} .circle{margin-top:0px} .mypage{height:100%;} .mui-table-view .mui-media-object { line-height: 45px; max-width: 45px; height: 45px; } </style><script>import tab from "../public/tab"import pull from "../public/pull" export default {  mounted() {   this.changemes();  },  components: {tab,pull},  data() {   return {     tab:0,     count:0,     list: []   }  },   computed:{      cmd:function(){    switch(this.tab){     case 0: return "Member/oneLevel";     case 1: return "Member/twoLevel";    }       }   },   methods: {    type(num){       switch (~~num) {     case 1: return "遊客";     case 2: return "使用者";     case 3: return "粉絲";     case 4: return "美人";     case 5: return "賣手";     case 6: return "合伙人";     case 7: return "加盟商";    }     return "未知";    },   tabchange({index, data}) {    this.tab = index;    },   changemes(){    this.list=null;     this.$api(this.cmd).then(list => {       this.count=list.count;      this.list=list.list;         });   }  },  watch:{   tab:function(){    this.changemes();    }  } }</script>

以上這篇vue重新整理和tab切換執行個體就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.