vue頭部導航動態(tài)點擊處理方法
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實現(xiàn)動態(tài)頭部
h5項目中,經(jīng)常用到的頭部是樣式是一致的,只是左右按鈕和中間標題會不一致。
vue主打組件化,為了減少代碼冗余,可以將頭部提取成一個單獨的組件。接下來考慮是否需要左右按鈕,是否固定在頁面上不動,中間標題是否為動態(tài)。
先寫一個簡單的頭部,position設(shè)置成變量customFixed。左右按鈕通過<slot>來控制。中間標題設(shè)置成變量customTitle通過父子組件傳值過來。
設(shè)置好樣式以后給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>
總結(jié)
以上所述是小編給大家介紹的vue頭部導航動態(tài)點擊處理方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue使用Echarts實現(xiàn)數(shù)據(jù)可視化的方法詳解
這篇文章主要為大家詳細介紹了Vue使用Echarts實現(xiàn)數(shù)據(jù)可視化的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-03-03關(guān)于VanCascader默認值(地址code轉(zhuǎn)換)
這篇文章主要介紹了關(guān)于VanCascader默認值(地址code轉(zhuǎn)換),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07vue在install時node-sass@4.14.1?postinstall:node?scripts/buil
最近在npm install 的時候遇到了個問題,所以給大家總結(jié)下,下面這篇文章主要給大家介紹了關(guān)于vue在install時node-sass@4.14.1?postinstall:node?scripts/build.js錯誤的解決方法,需要的朋友可以參考下2023-05-05vue本地打開build后生成的dist文件夾index.html問題
這篇文章主要介紹了vue本地打開build后生成的dist文件夾index.html問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧2019-09-09