1:DATA中兩個變量,
data: { nav:['頭條1','頭條2'], ins:0,//記錄當前點擊的INDEX },
2:
<div v-for="(item,index) in nav" :class="index == ins ? 'swiper-slide swiper_active' : 'swiper-slide' " @click="topClick(index)">{{item}}</div>
3:mothods:
topClick:function(i){ var t=this; t.ins=i; },
ps:下面看下vue實現動態頭部
h5項目中,經常用到的頭部是樣式是一致的,只是左右按鈕和中間標題會不一致。
vue主打組件化,為了減少代碼冗余,可以將頭部提取成一個單獨的組件。接下來考慮是否需要左右按鈕,是否固定在頁面上不動,中間標題是否為動態。
先寫一個簡單的頭部,position設置成變量customFixed。左右按鈕通過<slot>來控制。中間標題設置成變量customTitle通過父子組件傳值過來。
設置好樣式以后給customFixed和customTitle默認值和類型。
<template> <div id="header" :style="{'position' : customFixed ? 'fixed' : 'absolute'}"> <slot name="left"></slot> {{customTitle}} <slot name="right"></slot> </div></template><script> export default { name: "my-header", props:{ customTitle : { type : String, default : '標題' }, customFixed: { type: Boolean, default: false } } }</script><style scoped>#header{ width: 100%;height: 40px;background: #666;color: white;text-align: center;line-height: 40px; position: absolute;left:0;top: 0;z-index: 10;} #header button {height: 100%;padding: 0 50px;} #header button:nth-of-type(1){float: left} #header button:nth-of-type(2){float: right}</style>在用到頭部的地方:<template> <div id="app"> <my-header custom-title="通訊錄" custom-fixed> <button @click="backBtn" slot="left">返回</button> <button @click="homeBtn" slot="right">主頁</button> </my-header> </div></template>
總結
以上所述是小編給大家介紹的vue頭部導航動態點擊處理方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答