vue中多路由表頭吸頂實(shí)現(xiàn)的幾種布局方式
vue項(xiàng)目多路由表頭吸頂實(shí)現(xiàn)的幾種布局方式
因?yàn)轫?xiàng)目較大,有五個界面,每個界面有四個子組件,每個子組件都有一個table表格,需求是每個界面的每個table滾動到頂端表頭吸頂,所以嘗試用vux做這種需求,
一、先聊js。
A.首先在vux可以這樣設(shè)置。
1.在state文件中設(shè)置狀態(tài)。
techo:{
partsFixed:false,
repairFixed:false,
mateFixed:false,
outRepairFixed:false
}//吸頂狀態(tài)
2.在action中commit狀態(tài)。
export const setTecho=function ({commit},data) {
commit(types.UPDATETECHO, {data})
}
3.mutations中更新狀態(tài)。
[types.UPDATETECHO](state,{data}){
const {name,type,other} =data;
for (let i in state.techo) {
if(i===name){
state.techo[i]=other;
state.techo[name]=type;
}
}
}//更新吸頂狀態(tài)
B.在界面中我們可以這樣操作。
1、在methods中我們可以定義一個回調(diào)函數(shù)。
partScroll(){
const evalPart = this.$refs.evalPart,//evalPart為表格對象
evalTopTitle = document.querySelector('.fixedNav');//evalTopTitle為導(dǎo)航欄
if(evalPart){
let evalPartBottom = evalPart.getBoundingClientRect().bottom,
evalPartTop = evalPart.getBoundingClientRect().top,
evalTopTitleHeight = evalTopTitle.getBoundingClientRect().height;
evalPartTop<=evalTopTitleHeight && evalPartBottom>=evalTopTitleHeight?
this.$store.dispatch('setTecho',{name:"partsFixed",type:true,other:false})
:this.$store.dispatch('setTecho',{name:"partsFixed",type:false,other:false});
}
},
如果項(xiàng)目大,最好對函數(shù)進(jìn)行封裝放到全局混合。
scrollEvent(evalPart,evalTopTitle,name){
if(evalPart){//注意一定要對表格對象進(jìn)行判斷,因?yàn)楸砀袷莿討B(tài)添加的,可能值為空,會報(bào)錯。
let evalPartBottom = evalPart.getBoundingClientRect().bottom,
evalPartTop = evalPart.getBoundingClientRect().top,
evalTopTitleHeight = evalTopTitle.getBoundingClientRect().height;
evalPartTop<=evalTopTitleHeight && evalPartBottom>=evalTopTitleHeight?
this.$store.dispatch('setTecho',{name,type:true,other:false})
:this.$store.dispatch('setTecho',{name,type:false,other:false});
}
},
partScroll(){
const evalPart = this.$refs.evalPart,//evalPart為表格對象
evalTopTitle = document.querySelector('.fixedNav');//evalTopTitle為導(dǎo)航欄
this.scrollEvent(evalPart,evalTopTitle,'partsFixed')
}
2、在mouted里面進(jìn)行滾動監(jiān)聽。
mounted(){
window.addEventListener('scroll',this.partScroll);
}
3、最后記得在destroyed里面進(jìn)行銷毀。
destroyed () {
window.removeEventListener('scroll', this.partScroll)
}
總結(jié)
以上所述是小編給大家介紹的vue中多路由表頭吸頂實(shí)現(xiàn)的幾種布局方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
Vue3實(shí)現(xiàn)獲取驗(yàn)證碼按鈕倒計(jì)時(shí)效果
這篇文章主要介紹了Vue3實(shí)現(xiàn)獲取驗(yàn)證碼按鈕倒計(jì)時(shí)效果,用戶點(diǎn)擊獲取驗(yàn)證碼按鈕,發(fā)送請求給后端,按鈕失效,并且開始倒計(jì)時(shí)60秒;在此期間,用戶無法再次點(diǎn)擊按鈕,即使用戶刷新頁面,倒計(jì)時(shí)依然存在,直到倒計(jì)時(shí)完畢,按鈕恢復(fù),感興趣的小伙伴跟著小編一起來看看吧2024-10-10
Vuejs第六篇之Vuejs與form元素實(shí)例解析
本文通過實(shí)例給大家詳細(xì)介紹了Vuejs與form元素的相關(guān)知識,非常不錯,具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09
vue中pinia數(shù)據(jù)一直重復(fù)獲取之前的值的解決方法
這篇文章主要介紹了vue中pinia數(shù)據(jù)一直重復(fù)獲取之前的值的解決方法,如果想讓pinia數(shù)據(jù)不會重復(fù)獲取之前的值需要手動強(qiáng)制觸發(fā) Pinia store 的狀態(tài)更新,文中有詳細(xì)的解決方法,需要的朋友可以參考下2024-04-04
VsCode工具開發(fā)vue項(xiàng)目必裝插件清單(推薦!)
對于很多使用vscode編寫vue項(xiàng)目的新手同學(xué)來說,可能不知道使用什么插件,下面這篇文章主要給大家介紹了關(guān)于VsCode工具開發(fā)vue項(xiàng)目必裝插件的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
解決vue prop傳值default屬性如何使用,為何不生效的問題
這篇文章主要介紹了解決vue prop傳值default屬性如何使用,為何不生效的問題。具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09

