better-scroll插件

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>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值