export default {
name: 'List',
props: {
hotCities: Array,
cities: Object,
letter: String,
},
mounted() {
this.scrollList = new BScroll(this.$refs.warpper);
},
watch: {
letter() {
if(this.letter) {
const element = this.$refs[this.letter][0];
console.log(element);
this.scrollList.scrollToElement(element);
}
}
}
}
使用this定義this.scrollList = new BScroll(this.$refs.warpper);,這樣在別的地方調(diào)用就可以直接使用this...。如果使用let定義,在別處使用利用this.scrollList.scrollToElement(element);就會報錯scrollToElement找不到