• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
初心Syn
博客园    首页    新随笔    联系   管理    订阅  订阅
Vuejs选项卡案例

css

.active {
color: red;
border-bottom: 1px solid red;
}
ul li {
padding: 0 15px;
float: left;
list-style: none;
}

html

<div id="root">
<ul>
<li @click="toggle(index,tab.view)" v-for="(tab,index) in tabs" :class="{active: active == index}" :key='index'>{{ tab.type }}</li>
</ul>
<br>
<component :is="currentView"></component>

</div>

 

js

Vue.component("child1", {
template: '<p>hell child1</p>'
})
Vue.component("child2", {
template: '<p>hell child2</p>'
})
new Vue({
el: '#root',
data: {
currentView: 'child1',
active: 0,
tabs: [{
type: 'child1 tab',
view: 'child1'
}, {
type: 'child2 tab',
view: 'child2'
}]
},
methods: {
toggle(i, v) {
this.active = i;
this.currentView = v
}
}
})

不忘初心,方得始终,初心易得,始终难守。
posted on 2017-12-04 15:53  初心Syn  阅读(616)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3