better-scroll外掛
阿新 • • 發佈:2019-01-07
1.
better-scroll 託管在 Npm 上,執行如下命令安裝:
npm install better-scroll --save
接下來就可以在程式碼中引入了,webpack 等構建工具都支援從 node_modules 裡引入程式碼:
import BScroll from 'better-scroll'
2.所需頁面引入。
<template> <div class="hello"> <h1>{{ msg }}</h1> <el-button>預設按鈕</el-button> <el-button @click="visible=true" type="primary">主要按鈕</el-button> <el-button type="text">文字按鈕</el-button> <el-dialog v-model="visible" title="Hello world"> <p>歡迎使用 Element</p> </el-dialog> <div style=""> <h2>演示better scroll</h2> <div class="wrapper" ref="wrapper"> <ul class="content"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>4</li> <li>4</li> <li>4</li> <li>4</li> <li>4</li> <li>4</li> </ul> </div> </div> </div> </template> <script> import BScroll from 'better-scroll' export default { name: 'hello', data () { return { msg: 'ElementUI框架演示:', visible:false } }, mounted(){ this.scroll = new BScroll( this.$refs.wrapper,{ scrollY:true, }) } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> .wrapper{ background-color: #e0e0e0; height: 120px; overflow: hidden; } </style>
補充:
<script> import BScroll from 'better-scroll' export default{ name:'home', components:{ bottom }, created(){ console.log('created') this.$nextTick(() => { setTimeout(()=>{ this.initScroll() },20) }) }, methods:{ initScroll(){ if(!this.rScroll){ this.rScroll = new BScroll(this.$refs.wrapper,{ scrollY:true, click:true, }) }else { this.rScroll.refresh(); } } } } </script>