Skip to content

Commit

Permalink
Pullup: Fix default params bug
Browse files Browse the repository at this point in the history
  • Loading branch information
airyland committed Apr 20, 2016
1 parent d7abec2 commit 63337c9
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions src/components/scroller/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ import XScroll from 'vux-xscroll/build/cmd/xscroll.js'
import Pulldown from 'vux-xscroll/build/cmd/plugins/pulldown'
import Pullup from 'vux-xscroll/build/cmd/plugins/pullup'
const pulldownDefaultConfig = {
const pulldownDefaultConfig = () => ({
content: 'Pull Down To Refresh',
height: 60,
autoRefresh: false,
downContent: 'Pull Down To Refresh',
upContent: 'Release To Refresh',
loadingContent: 'Loading...',
clsPrefix: 'xs-plugin-pulldown-'
}
})
const pullupDefaultConfig = {
const pullupDefaultConfig = () => ({
content: 'Pull Up To Refresh',
pullUpHeight: 60,
height: 40,
autoRefresh: false,
downContent: 'Release To Refresh',
upContent: 'Pull Up To Refresh',
loadingContent: 'Loading...',
clsPrefix: 'xs-plugin-pullup-'
}
})
export default {
props: {
Expand Down Expand Up @@ -101,9 +102,8 @@ export default {
this.uuid = Math.random().toString(36).substring(3, 8)
},
ready () {
const _this = this
const uuid = Math.random().toString(36).substring(3, 8)
this.$el.setAttribute('id', `vux-scroller-${uuid}`)
console.log(this.uuid)
this.$el.setAttribute('id', `vux-scroller-${this.uuid}`)
let content = null
const slotChildren = this.$el.querySelector('.xs-container').childNodes
for (let i = 0; i < slotChildren.length; i++) {
Expand All @@ -117,7 +117,7 @@ export default {
}
this._xscroll = new XScroll({
renderTo: `#vux-scroller-${uuid}`,
renderTo: `#vux-scroller-${this.uuid}`,
lockX: this.lockX,
lockY: this.lockY,
scrollbarX: this.scrollbarX,
Expand All @@ -134,34 +134,34 @@ export default {
if (this.usePulldown) {
// if use slot=pulldown
let container = this.$el.querySelector('div[slot="pulldown"]')
let config = Object.assign(pulldownDefaultConfig, this.pulldownConfig)
let config = Object.assign(pulldownDefaultConfig(), this.pulldownConfig)
if (container) {
config.container = container
}
_this.pulldown = new Pulldown(config)
_this._xscroll.plug(this.pulldown)
_this.pulldown.on('loading', function (e) {
_this.$dispatch('pulldown:loading', _this.uuid)
this.pulldown = new Pulldown(config)
this._xscroll.plug(this.pulldown)
this.pulldown.on('loading', (e) => {
this.$dispatch('pulldown:loading', this.uuid)
})
_this.pulldown.on('statuschange', function (val) {
_this.pulldownStatus = val.newVal
this.pulldown.on('statuschange', (val) => {
this.pulldownStatus = val.newVal
})
}
if (this.usePullup) {
// if use slot=pullup
let container = this.$el.querySelector('div[slot="pullup"]')
let config = Object.assign(pullupDefaultConfig, _this.pullupConfig)
let config = Object.assign(pullupDefaultConfig(), this.pullupConfig)
if (container) {
config.container = container
}
_this.pullup = new Pullup(config)
_this._xscroll.plug(this.pullup)
_this.pullup.on('loading', function (e) {
_this.$dispatch('pullup:loading', _this.uuid)
this.pullup = new Pullup(config)
this._xscroll.plug(this.pullup)
this.pullup.on('loading', (e) => {
this.$dispatch('pullup:loading', this.uuid)
})
_this.pullup.on('statuschange', function (val) {
_this.pullupStatus = val.newVal
this.pullup.on('statuschange', (val) => {
this.pullupStatus = val.newVal
})
}
Expand All @@ -171,30 +171,36 @@ export default {
'pulldown:reset': function (uuid) {
// set pulldown status to default
this.pulldownStatus = 'default'
const _this = this
if (uuid === _this.uuid) {
_this.pulldown.reset(function () {
if (uuid === this.uuid) {
this.pulldown.reset(() => {
// repaint
_this._xscroll.render()
this._xscroll.render()
})
}
},
'pullup:reset': function (uuid) {
// set pulldown status to default
this.pullupStatus = 'default'
const _this = this
if (uuid === _this.uuid) {
_this.pullup.complete()
_this._xscroll.render()
if (uuid === this.uuid) {
this.pullup.complete()
this._xscroll.render()
}
},
'pullup:done': function (uuid) {
this._xscroll.unplug(this.pullup)
}
},
beforeDestroy () {
if (this.pullup) {
this._xscroll.unplug(this.pullup)
this.pullup.pluginDestructor()
}
if (this.pulldown) {
this._xscroll.unplug(this.pulldown)
this.pulldown.pluginDestructor()
}
this._xscroll.destroy()
this.pulldown && this.pulldown.pluginDestructor()
this._xscroll = null
}
}
</script>
Expand Down

0 comments on commit 63337c9

Please sign in to comment.