赞
踩
uni-app切换导航栏1
//tab.vue <template> <div class="tabDemo w100 textc"> <div class="fw500 ft28 c0" v-for="(item,index) in tabs" :key="index" @click="changeTab(index)"> {{item}} <div class="line" v-if="tabIndex === index"></div> </div> </div> </template> <script> export default { name:'tab', props: { tabs: Array, tabIndex: Number }, data() { return { }; }, watch: { tabs(newVal) { this.tabs = newVal //对父组件传过来的值进行监听,如果改变也对子组件内部的值进行改变 } }, methods:{ changeTab(index){ console.log('tabIndex', this.tabIndex) this.$emit('tabsChange', index) } } } </script> <style scoped> .tabDemo{ height: 88px; background: #FFFFFF; display: flex; position: relative } div{ position: relative; flex: 1; line-height: 100px; font-size: 28px; font-family: PingFangSC-Medium, PingFang SC; /* font-weight: 500; */ color: #000000; font-weight: bold; } .line{ position: absolute; bottom: 0; bottom: 0; width: 50px; height: 7px; background: #FF8C00; border-radius: 4px; left:50%; margin-left:-25px; } </style>
<template> <div id='Three'> <!-- 切换导航部分 --> <Tab :tabs='tabs' :tabIndex='status' @tabsChange='tabsChange'></Tab> </div> </template> <script> import Tab from './tab/tab' export default { components:{ Tab, }, data() { return { status:0, tabs: ['未支付', '已结款', '全部'], }; }, methods:{ tabsChange(value){ console.log('更改tab', value) this.status = value; }, } } </script>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。