vue中多路由表头吸顶实现的几种布局方式
网络编程 2021-07-04 15:50www.168986.cn编程入门
这篇文章主要介绍了vue项目多路由表头吸顶实现的几种布局方式,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
vue项目多路由表头吸顶实现的几种布局方式
因为项目较大,有五个界面,每个界面有四个子组件,每个子组件都有一个table表格,需求是每个界面的每个table滚动到顶端表头吸顶,所以尝试用vux做这种需求,
一、先聊js。
A.在vux可以这样设置。
1.在state文件中设置状态。
techo:{ partsFixed:false, repairFixed:false, mateFixed:false, outRepairFixed:false }//吸顶状态
2.在action中mit状态。
export const setTecho=function ({mit},data) { mit(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()., 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()., 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中多路由表头吸顶实现的几种布局方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
如果你觉得本文对你有帮助,欢迎网络推广网站推广转载,烦请注明出处,谢谢!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指