Vue實(shí)現(xiàn)簡單選項(xiàng)卡功能
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)簡單選項(xiàng)卡的具體代碼,供大家參考,具體內(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)選項(xiàng)卡及選項(xiàng)卡切換效果
- 使用vue.js寫一個tab選項(xiàng)卡效果
- Vue.js組件tabs實(shí)現(xiàn)選項(xiàng)卡切換效果
- vue插件tab選項(xiàng)卡使用小結(jié)
- Vue.js組件tab實(shí)現(xiàn)選項(xiàng)卡切換
- vue中選項(xiàng)卡點(diǎn)擊切換且能滑動切換功能的實(shí)現(xiàn)代碼
- vuejs實(shí)現(xiàn)標(biāo)簽選項(xiàng)卡動態(tài)更改css樣式的方法
- Vue.js tab實(shí)現(xiàn)選項(xiàng)卡切換
- vue動態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果
- vue中用動態(tài)組件實(shí)現(xiàn)選項(xiàng)卡切換效果
相關(guān)文章
vue3封裝echarts圖表數(shù)據(jù)無法渲染到頁面問題
這篇文章主要介紹了vue3封裝echarts圖表數(shù)據(jù)無法渲染到頁面問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09
unplugin-svg-component優(yōu)雅使用svg圖標(biāo)指南
這篇文章主要為大家介紹了unplugin-svg-component優(yōu)雅使用svg圖標(biāo)指南,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Element UI框架中巧用樹選擇器的實(shí)現(xiàn)
這篇文章主要介紹了Element UI框架中巧用樹選擇器的實(shí)現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-12-12
Vue使用v-viewer實(shí)現(xiàn)圖片預(yù)覽
這篇文章主要為大家詳細(xì)介紹了Vue使用v-viewer實(shí)現(xiàn)圖片預(yù)覽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-10-10
Vue.js圖片滑動驗(yàn)證的實(shí)現(xiàn)示例
為了防止有人惡意使用腳本進(jìn)行批量操作,會設(shè)置圖片滑動驗(yàn)證,本文就介紹了Vue.js圖片滑動驗(yàn)證的實(shí)現(xiàn)示例,感興趣的可以了解一下2023-05-05

