安裝
// 歷史版本TypeScript中import會(huì)不兼容,所以需要使用新版本
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() {
// 水平滑動(dòng)需要設(shè)置
(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
// 注意父容器的寬度必須設(shè)置
// 我這邊設(shè)置的寬度是 100%
記錄,祝好!
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。