其實官方示例給的挺明確的,只是我一開始自作聰明。。。
把<template></template>給干掉了,然后就各種各樣的不能實現,
我總結下:
1.首先給一個要返回頂部的地方,而且得是個有高度的
例子: <div class='firset-herad></div> 這是我最外層的div,給.firset-herad設置一個高度,height:100%
2.在<div class='firset-herad>中最上邊寫<template>
例子:<div class='firset-herad'>
<template>
<el-backtop
target='.firset-herad' //觸發滾動的對象
:right='40' //距離右邊的距離
:bottom='100' //距離底部的距離
;visibility-height='400'> //滾動高度達到此參數值才出現,控制顯示與隱藏
<div>
<i class='el-icon-top'></i> //我這里使用的element-ui中的圖標當做按鈕
</div>
</el-backtop>
</template>
</div>