vue tabNav 点击

本文介绍了一个使用Vue.js编写的简易Tab导航组件,通过v-for循环遍历数据并利用@click事件来切换选中的Tab项,同时实现了相应的样式变化。
 1 <template>
 2     <div class="content">
 3         <header class="tab_nav">
 4             <div v-for="(item,index) in tabNav" :key="index" @click = "selected(index, $event)" :class="{'active':item.active}">
 5                 <img :src="item.imgUrl" alt="icon">
 6                 <span>{{item.title}}</span>
 7             </div>
 8         </header>
 9         <main></main>
10         <footer></footer>
11     </div>
12 </template>
13 
14 <script>
15     export default {
16         data() {
17             return {
18                 tabNav:[
19                     {title:'我参与的',active:true,imgUrl:'/src/images/index/participate.png'},
20                     {title:'我发布的',active:false,imgUrl:'/src/images/index/publish.png'},
21                     {title:'我抽奖的',active:false,imgUrl:'/src/images/index/luck_draw.png'},
22                 ]
23             }
24         },
25         methods: {
26             selected: function(index) {
27                 this.tabNav.forEach(e => e.active = false);
28                 this.tabNav[index].active = true;
29             }
30         }
31     }
32 </script>
33 
34 <style scoped lang="less">
35     .border{
36         content: '';
37         display: block;
38         width: 1px;
39         height: 1.5rem;
40         background: #D9D9D9;
41         position: absolute;
42         top: 0.75rem;
43     }
44     .tab_nav{
45         display: flex;
46         width: 100%;
47         height: 2.5rem;
48         background: #fff;
49         opacity: 0.5rem;
50         &>div{
51             height: 2.5rem;
52             width: 33.33%;
53             opacity: 0.5;
54             text-align: center;
55             &:nth-of-type(2) {
56                 position: relative;
57                 &::before{
58                     .border;
59                     left: 0;
60                 }
61                 &::after{
62                     .border;
63                     right: 0;
64                 }
65             }
66             &>img{
67                 width: 1rem;
68                 height: 1rem;
69                 display: block;
70                 margin:  0.5rem auto 0;
71             }
72             &>span{
73                 display: block;
74                 font-size: 0.5rem;
75                 color: #69728E;
76                 line-height: 0.8rem;
77             }
78         }
79         &>div.active {
80             color: #69728E;
81             opacity: 1;
82         }84 
85 
86     }
87 
88 </style>

 

转载于:https://www.cnblogs.com/1032473245jing/p/8920828.html

(found in <Root>) warn @ vue.js:634 flushSchedulerQueue @ vue.js:4332 (匿名) @ vue.js:1998 flushCallbacks @ vue.js:1924 Promise.then timerFunc @ vue.js:1951 nextTick @ vue.js:2008 queueWatcher @ vue.js:4419 update @ vue.js:4559 notify @ vue.js:745 reactiveSetter @ vue.js:1070 proxySetter @ vue.js:4643 callback @ VM48745:3 invokeWithErrorHandling @ vue.js:1872 invoker @ vue.js:2197 invokeWithErrorHandling @ vue.js:1872 Vue.$emit @ vue.js:3904 set @ element.js:10 Pi.i.on.change @ element.js:10 invokeWithErrorHandling @ vue.js:1872 invoker @ vue.js:2193 original._wrapper @ vue.js:7591 vue.js:634 [Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'name')" found in ---> <TabNav> at packages/tabs/src/tab-nav.vue <ElTabs> at packages/tabs/src/tabs.vue <Root> warn @ vue.js:634 logError @ vue.js:1902 globalHandleError @ vue.js:1897 handleError @ vue.js:1857 Vue._render @ vue.js:3574 updateComponent @ vue.js:4082 get @ vue.js:4494 run @ vue.js:4569 flushSchedulerQueue @ vue.js:4327 (匿名) @ vue.js:1998 flushCallbacks @ vue.js:1924 Promise.then timerFunc @ vue.js:1951 nextTick @ vue.js:2008 Vue.$nextTick @ vue.js:3545 updated @ element.js:10 invokeWithErrorHandling @ vue.js:1872 callHook @ vue.js:4236 callUpdatedHooks @ vue.js:4368 flushSchedulerQueue @ vue.js:4353 (匿名) @ vue.js:1998 flushCallbacks @ vue.js:1924 Promise.then timerFunc @ vue.js:1951 nextTick @ vue.js:2008 queueWatcher @ vue.js:4419 update @ vue.js:4559 notify @ vue.js:745 reactiveSetter @ vue.js:1070 proxySetter @ vue.js:4643 callback @ VM48745:3 invokeWithErrorHandling @ vue.js:1872 invoker @ vue.js:2197 invokeWithErrorHandling @ vue.js:1872 Vue.$emit @ vue.js:3904 set @ element.js:10 Pi.i.on.change @ element.js:10 invokeWithErrorHandling @ vue.js:1872 invoker @ vue.js:2193 original._wrapper @ vue.js:7591 vue.js:1906 TypeError: Cannot read properties of undefined (reading 'name') at element.js:10:376336 at Proxy.renderList (vue.js:2653:18) at Proxy.render (element.js:10:376307) at Vue._render (vue.js:3572:24) at VueComponent.updateComponent (vue.js:4082:23) at Watcher.get (vue.js:4494:27) at Watcher.run (vue.js:4569:24) at flushSchedulerQueue (vue.js:4327:15) at Array.<anonymous> (vue.js:1998:14) at flushCallbacks (vue.js:1924:16)
08-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值