您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)Vue如何實(shí)現(xiàn)簡(jiǎn)單選項(xiàng)卡功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
具體內(nèi)容如下
vue-tab-demo
App.vue
<template> <div id="app"> <Tab/> </div> </template> <script> import Tab from './components/Tab' export default { name: 'App', components: { Tab } } </script> <style> ul, li { list-style: none; } .clearfix { zoom: 1; } .clearfix:after { display: block; content: ''; clear: both; } </style>
先布局,寫好樣式
Tab.vue
<template> <div id="tab"> <div class="tab-bar clearfix"> <a href="javascript:;">HTML</a> <a href="javascript:;">CSS</a> <a href="javascript:;">JavaScript</a> <a href="javascript:;" class="active">Vue</a> </div> <div class="tab-con"> <div>HTML</div> <div>CSS</div> <div>JavaScript</div> <div class="light">Vue</div> </div> </div> </template> <script> export default { data () { return { } }, methods: { } } </script> <style scoped> #tab { width: 400px; border: 1px solid #ccc; margin: 60px auto 0; } .tab-bar { width: 400px; background-color: #ccc; } .tab-bar a { float: left; width: 100px; height: 40px; line-height: 40px; text-align: center; text-decoration: none; color: #000; } .tab-con div { text-align: left; height: 100px; display: none; } .tab-bar .active { background-color: #0099ff; } .tab-con .light { display: block; } </style>
渲染數(shù)據(jù)后,上面Tab.vue修改后如下:
<template> <div id="tab"> <div class="tab-bar clearfix"> <a href="javascript:;" @click="tab(index)" v-for="(item,index) in items" :class="{active : index===curId}" >{{item.item}}</a> </div> <div class="tab-con"> <div v-show="index===curId" v-for="(content, index) in contents" >{{content.content}}</div> </div> </div> </template> <script> export default { data () { return { curId: 0, items: [ {item: 'HTML'}, {item: 'CSS'}, {item: 'JavaScript'}, {item: 'Vue'}, ], contents: [ {content: 'HTML'}, {content: 'CSS'}, {content: 'JavaScript'}, {content: 'Vue'}, ] } }, methods: { tab (index) { this.curId = index; } } } </script> <style scoped> #tab { width: 400px; border: 1px solid #ccc; margin: 60px auto 0; } .tab-bar { width: 400px; background-color: #ccc; } .tab-bar a { float: left; width: 100px; height: 40px; line-height: 40px; text-align: center; text-decoration: none; color: #000; } .tab-bar .active { background-color: #0099ff; } .tab-con div { text-align: left; height: 100px; } </style>
關(guān)于“Vue如何實(shí)現(xiàn)簡(jiǎn)單選項(xiàng)卡功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。