Vue實(shí)現(xiàn)簡單選項卡功能
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)簡單選項卡的具體代碼,供大家參考,具體內(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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)選項卡及選項卡切換效果
- 使用vue.js寫一個tab選項卡效果
- Vue.js組件tabs實(shí)現(xiàn)選項卡切換效果
- vue插件tab選項卡使用小結(jié)
- Vue.js組件tab實(shí)現(xiàn)選項卡切換
- vue中選項卡點(diǎn)擊切換且能滑動切換功能的實(shí)現(xiàn)代碼
- vuejs實(shí)現(xiàn)標(biāo)簽選項卡動態(tài)更改css樣式的方法
- Vue.js tab實(shí)現(xiàn)選項卡切換
- vue動態(tài)組件實(shí)現(xiàn)選項卡切換效果
- vue中用動態(tài)組件實(shí)現(xiàn)選項卡切換效果
相關(guān)文章
vue項目element-ui級聯(lián)選擇器el-cascader回顯的問題及解決
這篇文章主要介紹了vue項目element-ui級聯(lián)選擇器el-cascader回顯的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
vue的axios請求改變content-type為form-data問題
這篇文章主要介紹了vue的axios請求改變content-type為form-data問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
vue props傳值失敗 輸出undefined的解決方法
今天小編就為大家分享一篇vue props傳值失敗 輸出undefined的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09
uniapp項目國際化標(biāo)準(zhǔn)的配置與實(shí)現(xiàn)
UniApp是一種基于Vue.js的跨平臺開發(fā)框架,可以快速地開發(fā)同時運(yùn)行在多個平臺的應(yīng)用程序,這篇文章主要介紹了uniapp項目國際化標(biāo)準(zhǔn)的配置與實(shí)現(xiàn),需要的朋友可以參考下2023-11-11
Vue ECharts餅圖實(shí)現(xiàn)方法詳解
這篇文章主要介紹了在vue.js中,使用echarts組件,創(chuàng)建一個餅圖,并且獲取餅圖的數(shù)據(jù)和屬性,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12
Vue Router動態(tài)路由使用方法總結(jié)
這篇文章主要介紹了Vue Router動態(tài)路由使用方法總結(jié),需要的朋友可以參考下2023-10-10

