美文网首页
TypeScript之Better-Scoll 记录

TypeScript之Better-Scoll 记录

作者: 我把今生当成了来世 | 来源:发表于2019-10-31 17:16 被阅读0次

传送 better-scroll官网

安装

// 历史版本TypeScript中import会不兼容,所以需要使用新版本
npm install @better-scroll/core@next --save

使用示例

// HTML
<div id="topMenu" class="top_menu">
    <div ref="topMenuRoot">
      <div class="menu_item" v-for="(item, index) in 4" :key="index">{{ item }}</div>
    </div>
</div>

// TS
<script lang="ts">
import { Vue } from "vue-property-decorator";
import BScroll from "@better-scroll/core";

export default class Home extends Vue {
  _initScroll() {
    // 水平滑动需要设置
    (this.$refs.topMenuRoot as HTMLDivElement).style.width = `460px`;

    this.$nextTick(() => {
      new BScroll('#topMenu', {
        startX: 0,
        scrollX: true,
        scrollY: false,
        click: false
      });
    });
  }

  created() {
    this.$nextTick(() => {
      this._initScroll();
    })
  }
}
</script>

// Less
// 注意父容器的宽度必须设置
// 我这边设置的宽度是 100% 
记录,祝好!

相关文章

网友评论

      本文标题:TypeScript之Better-Scoll 记录

      本文链接:https://www.haomeiwen.com/subject/lnvtbctx.html