国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue中多路由表頭吸頂實現的幾種布局方式

2024-05-06 15:40:49
字體:
來源:轉載
供稿:網友

vue項目多路由表頭吸頂實現的幾種布局方式

因為項目較大,有五個界面,每個界面有四個子組件,每個子組件都有一個table表格,需求是每個界面的每個table滾動到頂端表頭吸頂,所以嘗試用vux做這種需求,

一、先聊js。

A.首先在vux可以這樣設置。

1.在state文件中設置狀態。

techo:{ partsFixed:false, repairFixed:false, mateFixed:false, outRepairFixed:false }//吸頂狀態

2.在action中commit狀態。

export const setTecho=function ({commit},data) { commit(types.UPDATETECHO, {data})}

3.mutations中更新狀態。

[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;  } } }//更新吸頂狀態

B.在界面中我們可以這樣操作。

1、在methods中我們可以定義一個回調函數。

partScroll(){ const evalPart = this.$refs.evalPart,//evalPart為表格對象   evalTopTitle = document.querySelector('.fixedNav');//evalTopTitle為導航欄 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}); } },

  如果項目大,最好對函數進行封裝放到全局混合。

scrollEvent(evalPart,evalTopTitle,name){ if(evalPart){//注意一定要對表格對象進行判斷,因為表格是動態添加的,可能值為空,會報錯。  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為導航欄  this.scrollEvent(evalPart,evalTopTitle,'partsFixed')}

2、在mouted里面進行滾動監聽。

mounted(){ window.addEventListener('scroll',this.partScroll);}

3、最后記得在destroyed里面進行銷毀。

destroyed () { window.removeEventListener('scroll', this.partScroll)}

總結

以上所述是小編給大家介紹的vue中多路由表頭吸頂實現的幾種布局方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 教育| 白玉县| 鄂尔多斯市| 微博| 宣化县| 沾化县| 兰州市| 兴城市| 凤阳县| 通城县| 盐津县| 大安市| 栾城县| 剑阁县| 鱼台县| 石狮市| 乌兰浩特市| 桐城市| 通道| 徐州市| 威信县| 南华县| 察雅县| 德昌县| 和平区| 综艺| 澳门| 瓦房店市| 大同市| 高唐县| 辉南县| 雅江县| 娄底市| 将乐县| 乌恰县| 光泽县| 丹阳市| 镇赉县| 黄大仙区| 达拉特旗| 土默特右旗|