Vue中使用vue2-perfect-scrollbar制作滚动条
更新时间:2022年06月09日 09:15:13 作者:~疆
这篇文章主要介绍了Vue中使用vue2-perfect-scrollbar滚动条,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
官方地址:https://github.com/mercs600/vue2-perfect-scrollbar
下载:
cnpm i -S vue2-perfect-scrollbar
main.js中引用:
import PerfectScrollbar from 'vue2-perfect-scrollbar' import 'vue2-perfect-scrollbar/dist/vue2-perfect-scrollbar.css' Vue.use(PerfectScrollbar)
使用:
<template> <div class="aside"> <div class="aside-header"> <img src="https://lj-common.oss-cn-chengdu.aliyuncs.com/vue.png" style="width: 30px; height: 30px" /> <span style=" font-size: 20px; font-weight: 600; color: white; margin-left: 10px; " >xxx</span > </div> <div class="aside-menu"> <perfect-scrollbar @ps-scroll-y="onScroll" ref="scrollbar"> <el-menu default-active="1" class="el-menu-vertical-demo" background-color="#191A23" text-color="#fff" active-text-color="white" > <el-menu-item index="1" @click="$router.push({ path: '/download' })"> <span slot="title">demo</span> </el-menu-item> <el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item> <el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item ><el-menu-item index="3"> <span slot="title">test</span> </el-menu-item> <el-menu-item index="2" @click="$router.push({ path: '/test' })"> <span slot="title">test1</span> </el-menu-item> </el-menu> </perfect-scrollbar> </div> </div> </template> <script> export default { data() { return {}; }, methods: { onScroll(event) { console.log(this.$refs.scrollbar.ps, event); }, }, watch: { //路由改变时,滚动条回到顶部 $route() { this.$refs.scrollbar.$el.scrollTop = 0; }, }, }; </script> <style lang='scss' scoped> .aside { height: 100vh; .aside-header { height: 60px; background-color: #545c64; line-height: 60px; display: flex; align-items: center; justify-content: center; } .aside-menu { height: calc(100vh - 60px); background-color: #0b6dd0; //展开时宽度 .el-menu-vertical-demo:not(.el-menu--collapse) { width: 256px; } .el-menu { height: 100%; border: 0 !important; //垂直时,去除右侧白边 } //perfect-scrollbar默认的类名。自定义滚动条内容区域高度 .ps { height: 100%; } } } </style>
到此这篇关于Vue中使用vue2-perfect-scrollbar滚动条的文章就介绍到这了,更多相关vue2-perfect-scrollbar滚动条内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
vue项目实现减少app.js和vender.js的体积操作
这篇文章主要介绍了vue项目实现减少app.js和vender.js的体积操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-11-11antd vue中,如何在form表单中的自定义组件使用v-decorator
antd vue中,在form表单中的自定义组件使用v-decorator问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-04-04
最新评论