Below I will share with you an example of vue refresh and tab switching, which has a good reference value and I hope it will be helpful to everyone.
First write a subcomponent to hold the refreshed content, named pull (you can see it at the end of the example.)
Then reference the page to be refreshed
<template> <p class="fbjbox container"> <p 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> //点击价格会排序 </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:'商品详情'}" rel="external nofollow" v-for="item in list"> <p class="img"><img src="/static/imghwm/default1.png" data-src="item.goods_image" class="lazy" v-bind:/ alt="Implement refresh and tab switching in vue" ></p> <h4 id="item-goods-name">{{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 '../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>
The following is the subcomponent named pull.
<template> <p class="mui-scroll-wrapper" ref="box" v-bind:style="{top:top+'px'}"> <p class="mui-pull-top-pocket mui-block" v-bind:class="{'mui-visibility':obj.y>0}" v-if="down"> <p class="mui-pull" v-show="flag"> <p class="mui-pull-loading mui-icon" v-bind:class="{'mui-spinner': type==2,'mui-icon-pulldown':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 id="暂无内容">暂无内容</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 ? '-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>
An example of tab
<template> <p class="mypage"> <p class="fbjbox"> <p class="fbjbox1"> <tab ref="tab" :list="['一级合伙人'+count,'二级合伙人']" width="50%" @change="tabchange" /> </p> <p class="fbjbox2"> <template v-if="list!=null&&tab==0"> <h4 id="一级合伙人总数-count-人">一级合伙人总数{{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 lazy" src="/static/imghwm/default1.png" data-src="item.head_url" v-bind: / alt="Implement refresh and tab switching in vue" > <p class="mui-media-body"> {{item.vname}} <p class='mui-ellipsis'>{{item.identity}}</p> </p> </li> </ul> </template> <template v-if="list!=null&&tab==1"> <h4 id="二级合伙人总数-count-人">二级合伙人总数{{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>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. help.
Related articles:
How to dynamically bind the attributes of form elements in vue
Use Vue.set dynamically new in Vue Method of adding object attributes
There is no configuration method under dev-server.js in vue2.0
The above is the detailed content of Implement refresh and tab switching in vue. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
