1. 问题:使用el-backtop时,指定target对象为父级元素后不显示
目前我采用的方法是简单粗暴的删除target不指定对象, 也是能显现按钮,并且回到顶部。
<el-backtop :visibility-height="100">
<i class="el-icon-caret-top"></i>
</el-backtop>
有时间可以研究下
Element-ui
不用多说,用Vue
的基本都会用到它。但是它的官方文档却有些不严谨的地方,最近我就在弄一个返回顶部的功能的时候遇到坑了。废话不多说,先上官方文档示例介绍:
Scroll down to see the bottom-right button.
<template>
Scroll down to see the bottom-right button.
<el-backtop target=".page-component__scroll .el-scrollbar__wrap"></el-backtop>
</template>
这个是基础用法,自定义用法跟这个也差不多,就是中间加了些样式。 看起来这个例子很简单对不对,按照最简单的原则拿过来就用,Ctrl+C到自己项目后就等着出现回到顶部按钮,结果实际结果却令我大失所望,直接报错了。错误原因就是找不到
el-scrollbar__wrap
。
既然给出了原因,那解决应该很简单,不是找不到这个样式吗,那我就在外层套个
div
然后定义个class=el-scrollbar__wrap
,心想这下子应该是可以了吧。结果运行的时候错误是没有了,但是那个心心念念的回到顶部按钮怎么都出现不了,难道是我姿势不对?然后我就再外面又套了div class=page-component__scroll
,但是还是没有卵用。
终极使用示例:
html,body {
height: 100%;
}
<template>
<div id="app">
<div class="content">
<div class="backtop"></div>
<el-backtop target=".content .backtop"></el-backtop>
</div>
</div>
</template>
<style>
html,body {
height: 100%;
}
#app {
height: 100%;
}
.content {
height: 100%;
}
.backtop {
overflow: scroll;
height: 100%;
}
</style>