您好,登錄后才能下訂單哦!
1:DATA中兩個變量,
data: { nav:['頭條1','頭條2'], ins:0,//記錄當(dāng)前點(diǎn)擊的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實現(xiàn)動態(tài)頭部
h6項目中,經(jīng)常用到的頭部是樣式是一致的,只是左右按鈕和中間標(biāo)題會不一致。
vue主打組件化,為了減少代碼冗余,可以將頭部提取成一個單獨(dú)的組件。接下來考慮是否需要左右按鈕,是否固定在頁面上不動,中間標(biāo)題是否為動態(tài)。
先寫一個簡單的頭部,position設(shè)置成變量customFixed。左右按鈕通過<slot>來控制。中間標(biāo)題設(shè)置成變量customTitle通過父子組件傳值過來。
設(shè)置好樣式以后給customFixed和customTitle默認(rèn)值和類型。
<template> <div id="header" :> <slot name="left"></slot> {{customTitle}} <slot name="right"></slot> </div> </template> <script> export default { name: "my-header", props:{ customTitle : { type : String, default : '標(biāo)題' }, 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>
總結(jié)
以上所述是小編給大家介紹的vue頭部導(dǎo)航動態(tài)點(diǎn)擊處理方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。