vue刷新和tab切换实例


Posted in Javascript onFebruary 11, 2018

首先写个子组件用来放刷新的内容,命名为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切换实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
js 获取子节点函数 (兼容FF与IE)
Apr 18 Javascript
jQuery.autocomplete 支持中文输入(firefox)修正方法
Mar 10 Javascript
Javascript中的window.event.keyCode使用介绍
Apr 26 Javascript
js将iframe中控件的值传到主页面控件中的实现方法
Mar 11 Javascript
jQuery+.net实现浏览更多内容(改编php版本)
Mar 28 Javascript
js中indexof的用法详细解析
Dec 24 Javascript
JS获取当前日期时间并定时刷新示例
Mar 04 Javascript
详谈javascript异步编程
Feb 21 Javascript
AngularJS入门之动画
Jul 27 Javascript
AngularJS解决ng-if中的ng-model值无效的问题
Jun 21 Javascript
JS实现多张图片预览同步上传功能
Jun 23 Javascript
Vue 表情包输入组件的实现代码
Jan 21 Javascript
详解如何在vue项目中引入elementUI组件
Feb 11 #Javascript
vue-router配合ElementUI实现导航的实例
Feb 11 #Javascript
vue页面跳转后返回原页面初始位置方法
Feb 11 #Javascript
使用vue-router设置每个页面的title方法
Feb 11 #Javascript
解决使用Vue.js显示数据的时,页面闪现原始代码的问题
Feb 11 #Javascript
ajax请求+vue.js渲染+页面加载的示例
Feb 11 #Javascript
vue.js,ajax渲染页面的实例
Feb 11 #Javascript
You might like
无数据库的详细域名查询程序PHP版(5)
2006/10/09 PHP
基于PHP CURL用法的深入分析
2013/06/09 PHP
Yii的CDbCriteria查询条件用法实例
2014/12/04 PHP
php中magic_quotes_gpc对unserialize的影响分析
2014/12/16 PHP
laravel7学习之无限级分类的最新实现方法
2020/09/30 PHP
js window.onload 加载多个函数的方法
2009/11/02 Javascript
js数据验证集合、js email验证、js url验证、js长度验证、js数字验证等简单封装
2010/05/15 Javascript
jquery简单实现滚动条下拉DIV固定在头部不动
2013/11/25 Javascript
jQuery实现自定义下拉列表
2015/01/05 Javascript
jquery实现鼠标滑过显示提示框的方法
2015/02/05 Javascript
动态加载jQuery的方法
2015/06/16 Javascript
bootstrap网页框架的使用方法
2016/05/10 Javascript
必备的JS调试技巧汇总
2016/07/20 Javascript
使用jQuery Ajax 请求webservice来实现更简练的Ajax
2016/08/04 Javascript
jQuery实现页面下拉100像素出现悬浮窗口的方法
2016/09/05 Javascript
Jquery Easyui搜索框组件SearchBox使用详解(19)
2016/12/17 Javascript
ajax +NodeJS 实现图片上传实例
2017/06/06 NodeJs
利用JavaScript如何查询某个值是否数组内
2017/07/30 Javascript
CountUp.js数字滚动插件使用方法详解
2019/10/17 Javascript
浅谈vuex中store的命名空间
2019/11/08 Javascript
原生js实现二级联动菜单
2019/11/27 Javascript
JS实现放烟花效果
2020/03/10 Javascript
[45:40]Ti4 冒泡赛第二天NEWBEE vs NaVi 1
2014/07/15 DOTA
python字典的常用操作方法小结
2016/05/16 Python
Python部署web开发程序的几种方法
2017/05/05 Python
用Python一键搭建Http服务器的方法
2018/06/01 Python
python3中函数参数的四种简单用法
2018/07/09 Python
matplotlib部件之矩形选区(RectangleSelector)的实现
2021/02/01 Python
CAT鞋英国官网:坚固耐用的靴子和鞋
2016/10/21 全球购物
健身场所或家用健身设备:Life Fitness
2017/11/01 全球购物
澳大利亚领先的在线礼品网站:Gifts Australia
2020/08/15 全球购物
几道数据库的面试题或笔试题
2014/05/31 面试题
TCP/IP模型的分界线
2012/12/01 面试题
总务岗位职责
2013/11/19 职场文书
车辆管理制度范本
2015/08/05 职场文书
Mysql InnoDB 的内存逻辑架构
2022/05/06 MySQL