vue慕課網音樂項目手記:52-搜索列表scroll的實現以及scroll底部距離的刷新
阿新 • • 發佈:2018-06-13
CA javascrip short result class otto his turn arp
首先引入scroll組件,然後使用:
<scroll class="shortcut" :data="shortcut" ref="shortcut">
這裏的data是computed計算的來的,因為scroll裏面有兩組數據:
shortcut () { return this.hotKey.concat(this.searchHistory) // 當hotKey和History有一個發生變化的時候。computed就會重新計算。 }
而當query從有到無的時候,scroll不能自動刷新。所以需要做一點優化:
watch: { query (newQuery) { if (!newQuery) { // 當query從有到無的時候,手動刷新以下scroll setTimeout(() => { this.$refs.shortcut.refresh() }) } } }
底部距離的刷新
import { playListMixin } from ‘common/js/mixin‘ mixins: [playListMixin], handlePlayList (playList) { const bottom = this.playList.length > 0 ? ‘60px‘ : 0 this.$refs.shortcutWrapper.style.bottom = bottom this.$refs.shortcut.refresh() this.$refs.searchResult.style.bottom = bottom this.$refs.suggest.refresh() },
vue慕課網音樂項目手記:52-搜索列表scroll的實現以及scroll底部距離的刷新