搜索
首页web前端js教程在vue中实现刷新和tab切换

下面我就为大家分享一篇vue刷新和tab切换实例,具有很好的参考价值,希望对大家有所帮助。

首先写个子组件用来放刷新的内容,命名为pull(可以看例子最后面放的。)

然后再要刷新的页面引用

<template>
   <p class="fbjbox container">
   <p class="fbjbox1">
  <tab ref=&#39;tab&#39; :list="[&#39;推荐&#39;,&#39;热门&#39;,&#39;最新&#39;]" width="33%" @change=&#39;tabchange&#39; style="float:left"/>
 <span class="price" width="33%" @tap="change" >价格<span class="mui-icon mui-icon-arrowright"></span></span> //点击价格会排序
   </p>
  <p class="fbjbox2">
   
   <pull up="true" down="true" @up="next" @down="shuaxin" ref="pull">
   
    <p class="mui-row mui-col-xs-12 mui-clearfix">
      <span class="mui-col-xs-6" v-href="{name:&#39;商品详情&#39;}" rel="external nofollow" v-for="item in list">
       <p class="img"><img v-bind:src="item.goods_image"/></p>
       <h4>{{item.goods_name}}</h4>
       <p class="red1">¥{{item.goods_price}}</p>
      </span>
     </p>
   
   </pull>
  
  </p>
</p>
</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 &#39;../tab&#39;
import pull from &#39;../public/pull&#39;
 export default {
   created() {
   this.height = window.innerWidth * 40 / 64;
   this.is_zc = this.$route.query.is_zc == 1;
   this.uid = localStorage.getItem(&#39;uid&#39;);
   
  
  },
  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>
 <p class="mui-scroll-wrapper" ref="box" v-bind:style="{top:top+&#39;px&#39;}">
  <p class="mui-pull-top-pocket mui-block" v-bind:class="{&#39;mui-visibility&#39;:obj.y>0}" v-if="down">
   <p class="mui-pull" v-show="flag">
    <p class="mui-pull-loading mui-icon" v-bind:class="{&#39;mui-spinner&#39;: type==2,&#39;mui-icon-pulldown&#39;:type!=2}" v-bind:style="css1"></p>
    <p class="mui-pull-caption" v-if="type==0">下拉可以刷新</p>
    <p class="mui-pull-caption" v-if="type==1">释放立即刷新</p>
    <p class="mui-pull-caption" v-if="type==2">正在刷新</p>
   </p>
  </p>
  <p class="mui-scroll" @scrollstart.self="scrollstart" @scroll.self="scroll" @scrollbottom="scrollbottom">
   <slot>
    <p class="no-content">
     <i></i>
     <h4>暂无内容</h4>
    </p>
   </slot>
   <p class="mui-pull-bottom-pocket mui-block mui-visibility" v-if="type==4">
    <p class="mui-pull">
     <p 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;"></p>
<p class="mui-pull-caption mui-visibility">正在加载...</p>
</p>
</p>
<!--<p v-if="nodata" class="nodata">已经没有更多数据</p>-->
<p v-if="nodata" class="yqxtsdkn"></p>
</p>
</p>
</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 ? &#39;-webkit-transform 0.3s ease-in&#39; : "",
     transform: this.type > 0 ? &#39;rotate(180deg)&#39; : "",
     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>
 <p class="mypage">
 
   <p class="fbjbox">
    <p class="fbjbox1">
    <tab ref="tab" :list="[&#39;一级合伙人&#39;+count,&#39;二级合伙人&#39;]" width="50%" @change="tabchange" />
   </p>
   <p 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" />
         <p class="mui-media-body">
          {{item.vname}}
          <p class=&#39;mui-ellipsis&#39;>{{item.identity}}</p>
         </p>
       </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">
         <p class="mui-media-body" v-cloak>
          {{type(index)}}人数<p class="mui-pull-right">{{item}}</p>
         </p>
       </li>
       
      </ul> 
    </template>
    <!--<template v-if="list==null">
     <p class=" mui-text-center" style="padding: 50px;">
      
     <span class="mui-spinner"></span>
     </p>
    </template>-->
    <template v-if="list==[]">
     <p>暂无下线</p>
    </template>
   </p>
  </p>
 
 </p>
</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中如何动态绑定表单元素的属性

在Vue中使用Vue.set动态新增对象属性方法

在vue2.0中没有dev-server.js下配置方法

以上是在vue中实现刷新和tab切换的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
在JavaScript中替换字符串字符在JavaScript中替换字符串字符Mar 11, 2025 am 12:07 AM

JavaScript字符串替换方法详解及常见问题解答 本文将探讨两种在JavaScript中替换字符串字符的方法:在JavaScript代码内部替换和在网页HTML内部替换。 在JavaScript代码内部替换字符串 最直接的方法是使用replace()方法: str = str.replace("find","replace"); 该方法仅替换第一个匹配项。要替换所有匹配项,需使用正则表达式并添加全局标志g: str = str.replace(/fi

自定义Google搜索API设置教程自定义Google搜索API设置教程Mar 04, 2025 am 01:06 AM

本教程向您展示了如何将自定义的Google搜索API集成到您的博客或网站中,提供了比标准WordPress主题搜索功能更精致的搜索体验。 令人惊讶的是简单!您将能够将搜索限制为Y

构建您自己的Ajax Web应用程序构建您自己的Ajax Web应用程序Mar 09, 2025 am 12:11 AM

因此,在这里,您准备好了解所有称为Ajax的东西。但是,到底是什么? AJAX一词是指用于创建动态,交互式Web内容的一系列宽松的技术。 Ajax一词,最初由Jesse J创造

示例颜色json文件示例颜色json文件Mar 03, 2025 am 12:35 AM

本文系列在2017年中期进行了最新信息和新示例。 在此JSON示例中,我们将研究如何使用JSON格式将简单值存储在文件中。 使用键值对符号,我们可以存储任何类型的

10个jQuery语法荧光笔10个jQuery语法荧光笔Mar 02, 2025 am 12:32 AM

增强您的代码演示:开发人员的10个语法荧光笔 在您的网站或博客上共享代码片段是开发人员的常见实践。 选择合适的语法荧光笔可以显着提高可读性和视觉吸引力。 t

8令人惊叹的jQuery页面布局插件8令人惊叹的jQuery页面布局插件Mar 06, 2025 am 12:48 AM

利用轻松的网页布局:8个基本插件 jQuery大大简化了网页布局。 本文重点介绍了简化该过程的八个功能强大的JQuery插件,对于手动网站创建特别有用

10 JavaScript和JQuery MVC教程10 JavaScript和JQuery MVC教程Mar 02, 2025 am 01:16 AM

本文介绍了关于JavaScript和JQuery模型视图控制器(MVC)框架的10多个教程的精选选择,非常适合在新的一年中提高您的网络开发技能。 这些教程涵盖了来自Foundatio的一系列主题

什么是这个&#x27;在JavaScript?什么是这个&#x27;在JavaScript?Mar 04, 2025 am 01:15 AM

核心要点 JavaScript 中的 this 通常指代“拥有”该方法的对象,但具体取决于函数的调用方式。 没有当前对象时,this 指代全局对象。在 Web 浏览器中,它由 window 表示。 调用函数时,this 保持全局对象;但调用对象构造函数或其任何方法时,this 指代对象的实例。 可以使用 call()、apply() 和 bind() 等方法更改 this 的上下文。这些方法使用给定的 this 值和参数调用函数。 JavaScript 是一门优秀的编程语言。几年前,这句话可

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器