From db0326550c5c6e7ed64f71ce0c1caeac45eb7526 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 7 Mar 2019 17:40:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3swiper=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=8A=A8=E6=80=81=E8=AE=BE=E7=BD=AEcurrent-item-id?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../view/components/swiper-item/index.vue | 16 ------------ src/core/view/components/swiper/index.vue | 25 ++++++++----------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/core/view/components/swiper-item/index.vue b/src/core/view/components/swiper-item/index.vue index f3140b61bf..4fb92a2e58 100644 --- a/src/core/view/components/swiper-item/index.vue +++ b/src/core/view/components/swiper-item/index.vue @@ -12,14 +12,6 @@ export default { default: '' } }, - watch: { - itemId (val, oldVal) { - this._itemIdUpdated(val, oldVal) - } - }, - created () { - this._itemIdUpdated(this.itemId, this.itemId) - }, mounted: function () { var $el = this.$el $el.style.position = 'absolute' @@ -31,14 +23,6 @@ export default { callback() }) } - }, - methods: { - _itemIdUpdated (val, oldVal) { - var $parent = this.$parent - if ($parent && typeof $parent._itemIdUpdated === 'function') { - $parent._itemIdUpdated(this, val, oldVal) - } - } } } diff --git a/src/core/view/components/swiper/index.vue b/src/core/view/components/swiper/index.vue index 1adea0de48..1c9fbb537e 100644 --- a/src/core/view/components/swiper/index.vue +++ b/src/core/view/components/swiper/index.vue @@ -69,8 +69,7 @@ export default { currentItemIdSync: this.currentItemId || '', userTracking: false, currentChangeSource: '', - items: [], - itemIdItemMap: {} + items: [] } }, computed: { @@ -143,9 +142,6 @@ export default { displayMultipleItemsNumber () { this._resetLayout() } - // itemIdItemMap () { - // this._resetLayout() - // } }, created () { this._invalid = true @@ -172,14 +168,6 @@ export default { this._cancelSchedule() }, methods: { - _itemIdUpdated (item, val, oldVal) { - if (oldVal) { - this.$set(this.itemIdItemMap, oldVal, null) - } - if (val) { - this.$set(this.itemIdItemMap, val, item.$vnode) - } - }, _inintAutoplay (enable) { if (enable) { this._scheduleAutoplay() @@ -191,7 +179,16 @@ export default { * 页面变更检查和同步 */ _currentCheck () { - var current = this.items.indexOf(this.itemIdItemMap[this.currentItemId]) + var current = -1 + if (this.currentItemId) { + for (let i = 0, items = this.items; i < items.length; i++) { + let componentInstance = items[i].componentInstance + if (componentInstance && componentInstance.itemId === this.currentItemId) { + current = i + break + } + } + } if (current < 0) { current = Math.round(this.current) || 0 } -- GitLab