1. Install
cnpm install better-scroll --save
2. Introduction
import BScroll from "better-scroll";
3. Initialize
data() { return { scroll: null } }, methods: { initScroll() { this.scroll = new BScroll(this.$refs.area_scroll, { click: true }); } },
Gets the DOM object
this.$refs.area_scroll
This line is to get the dom
{ The Click: to true } This is a property method widget
4. We may be retrieved interfaces to get data and then scrolling
// request interface to get data to render the page is an asynchronous process, created the life cycle is not yet rendered dom, nextTick will use this callback method after rendering dom // initScroll Alphabet by the incoming the this . $ NextTick (( ) => { the this . refs.allcity.initScroll $ (); });
We retrieval interface created the life cycle, this time the page has not yet been rendered, we need to use this. $ NextTick this method
this. $ nextTick This approach allows us to complete mounted after the lifecycle callback method again, the operation of dom
Vue.nextTick () function: callback execution delay after the end of the next update cycle dom. Using this method immediately after modifying the data, obtained dom updated