Fixed: one page Swipe components error (#70)

This commit is contained in:
Kay 2017-08-09 14:48:46 +08:00 committed by 张敏
parent 93db67b964
commit 7bc8c5022a
3 changed files with 33 additions and 13 deletions

View File

@ -69,12 +69,6 @@ extend(Scroll.prototype, {
var leftOffset = offset - wrapWidth;
var rightOffset = offset + wrapWidth;
page = this.getCurrentPage();
if (page) {
page.style['-webkit-transform'] = 'translate3d(' + offset + 'px, 0, 0)';
page.style['display'] = 'block';
}
leftPage = this.pages[this.mapLoopPage(currentOffsetPage - 1)];
if (leftPage) {
if (Math.abs(leftOffset) <= wrapWidth) {
@ -96,6 +90,12 @@ extend(Scroll.prototype, {
}
}
}
page = this.getCurrentPage();
if (page) {
page.style['-webkit-transform'] = 'translate3d(' + offset + 'px, 0, 0)';
page.style['display'] = 'block';
}
},
movePage: function(dist, isEnd) {

View File

@ -10,6 +10,13 @@ export default {
beforeCreate() {
this.$parent.swipes.push(this);
},
destroyed() {
const index = this.$parent.swipes.indexOf(this)
if (index > -1) {
this.$parent.swipes.splice(index, 1)
}
}
};
</script>

View File

@ -36,11 +36,6 @@ export default {
},
mounted() {
const pages = this.$el.querySelectorAll('.van-swipe-item')
if (pages.length <= 1) {
return
}
this.input = new Input(this.$el, {
listenMoving: true
});
@ -66,10 +61,28 @@ export default {
}).on('autoPlay', function(dist, isEnd) {
scroll.movePage(dist.x, isEnd);
});
this.dummy = dummy
},
updated() {
this.scroll.update();
watch: {
swipes(value) {
if (this.autoPlay && value.length > 1) {
this.dummy.initMove()
} else {
this.dummy.clearMove()
}
this.scroll.update();
return value
},
autoPlay(value) {
if (value && this.swipes.length > 1) {
this.dummy.initMove()
} else {
this.dummy.clearMove()
}
return value
}
},
methods: {