- 执行命令
npm install better-scroll --save
- html代码块
<div class="homecontent" ref="wrapper">
<div>
<router-link to="/DriverAccount">
<el-card class="box-card">
</el-card>
</router-link>
<el-card class="box-card">
</el-card>
<el-card class="box-card">
</el-card>
<el-card class="box-card">
</el-card>
</div>
</div>
homecontent的样式:
.homecontent{
overflow: hidden;
position: absolute;
top: 1.4rem;
left: 0;
right: 0;
bottom: 0;
}
js中mounted挂载使用:
先引入 import Bscroll from 'better-scroll'
使用后会有个点击跳转路由失效问题 ,better-scroll 默认会阻止浏览器的原生 click 事件, 在mounted方法中定义click,
mounted() {
//解决点击失效问题
const options = {
click:true,
tap:true,
}
this.scroll = new Bscroll(this.$refs.wrapper,options)
},