Vue中使用vue2-perfect-scrollbar制作滾動(dòng)條
官方地址: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: { //路由改變時(shí),滾動(dòng)條回到頂部 $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; //展開時(shí)寬度 .el-menu-vertical-demo:not(.el-menu--collapse) { width: 256px; } .el-menu { height: 100%; border: 0 !important; //垂直時(shí),去除右側(cè)白邊 } //perfect-scrollbar默認(rèn)的類名。自定義滾動(dòng)條內(nèi)容區(qū)域高度 .ps { height: 100%; } } } </style>
到此這篇關(guān)于Vue中使用vue2-perfect-scrollbar滾動(dòng)條的文章就介紹到這了,更多相關(guān)vue2-perfect-scrollbar滾動(dòng)條內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue-cli3.x配置全局的scss的時(shí)候報(bào)錯(cuò)問題及解決
這篇文章主要介紹了vue-cli3.x配置全局的scss的時(shí)候報(bào)錯(cuò)問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04在Vue-cli里應(yīng)用Vuex的state和mutations方法
今天小編就為大家分享一篇在Vue-cli里應(yīng)用Vuex的state和mutations方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09關(guān)于vue v-for循環(huán)解決img標(biāo)簽的src動(dòng)態(tài)綁定問題
今天小編就為大家分享一篇關(guān)于vue v-for循環(huán)解決img標(biāo)簽的src動(dòng)態(tài)綁定問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-09-09如何使用vue slot創(chuàng)建一個(gè)模態(tài)框的實(shí)例代碼
這篇文章主要介紹了如何使用vue slot創(chuàng)建一個(gè)模態(tài)框,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05vue里的axios如何獲取本地json數(shù)據(jù)
這篇文章主要介紹了vue里的axios如何獲取本地json數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08