1:DATA中兩個(gè)變量,
創(chuàng)新互聯(lián)專注于衡東企業(yè)網(wǎng)站建設(shè),自適應(yīng)網(wǎng)站建設(shè),成都商城網(wǎng)站開發(fā)。衡東網(wǎng)站建設(shè)公司,為衡東等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
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實(shí)現(xiàn)動(dòng)態(tài)頭部
h6項(xiàng)目中,經(jīng)常用到的頭部是樣式是一致的,只是左右按鈕和中間標(biāo)題會(huì)不一致。
vue主打組件化,為了減少代碼冗余,可以將頭部提取成一個(gè)單獨(dú)的組件。接下來考慮是否需要左右按鈕,是否固定在頁面上不動(dòng),中間標(biāo)題是否為動(dòng)態(tài)。
先寫一個(gè)簡(jiǎn)單的頭部,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)航動(dòng)態(tài)點(diǎn)擊處理方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
新聞名稱:vue頭部導(dǎo)航動(dòng)態(tài)點(diǎn)擊處理方法
文章源于:http://jinyejixie.com/article14/ijdcde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、微信公眾號(hào)、企業(yè)網(wǎng)站制作、企業(yè)建站、網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)