vue2.0實現(xiàn)導航菜單切換效果
更新時間:2017年05月08日 11:09:29 作者:奈奈冪
這篇文章主要為大家詳細介紹了vue2.0實現(xiàn)導航菜單切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了vue2.0實現(xiàn)導航菜單切換的具體代碼,供大家參考,具體內容如下
css
*{
margin:0;
padding: 0;
}
ul li{
list-style: none;
}
.navul{
margin:100px auto 20px;
overflow: hidden;
}
.navul li{
background-color: #5597b4;
padding:18px 30px;
float:left;
color: #fff;
font-size: 18px;
cursor: pointer;
}
.active{
background-color: #5597b4;
}
.home .home,.new .new,.contact .contact,.service .service{
background-color: skyblue;
}
.checked{
background: #eff4f7;
}
html
<div id="nav">
<ul>
<li v-for="(relation,index) in relations" v-bind:id="relation.id" v-bind:id="relation.id" v-bind:class="{checked:index==nowIndex}" v-on:click="relationClick(index)">
<i></i>
<span class="">{{relation.text}}</span>
</li>
</ul>
</div>
js
<script src="js/vue.js" charset="utf-8"></script>
<script type="text/javascript">
var nav = new Vue({
el:'#nav',
data:{
relations: [
{text:'項目',id:'program'},
{text:'人員',id:'person'},
{text:'機構',id:'organization'},
{text:'技術',id:'tech'},
{text:'地區(qū)',id:'location'},
{text:'國家',id:'country'}
],
nowIndex:-1,
},
methods:{
relationClick:function(index){
this.nowIndex=index;
}
}
});
</script>
效果圖:

關于vue.js組件的教程,請大家點擊專題vue.js組件學習教程進行學習。
更多vue學習教程請閱讀專題《vue實戰(zhàn)教程》
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
Vue Element前端應用開發(fā)之整合ABP框架的前端登錄
VUE+Element 前端是一個純粹的前端處理,前面介紹了很多都是Vue+Element開發(fā)的基礎,從本章隨筆開始,就需要進入深水區(qū)了,需要結合ABP框架使用2021-05-05
Vite+Electron快速構建VUE3桌面應用的實現(xiàn)
本文主要介紹了Vite+Electron快速構建VUE3桌面應用的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-10-10

