Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fix directive instance condition
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Mar 21, 2020
1 parent c19482a commit 044629c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

### [4.0.3](https://github.com/surmon-china/vue-awesome-swiper/compare/v4.0.2...v4.0.3) (2020-03-21)

**Fixed**
- Directive instancing when `swiper.destroyed`

### [4.0.2](https://github.com/surmon-china/vue-awesome-swiper/compare/v4.0.1...v4.0.2) (2020-03-20)

### [4.0.1](https://github.com/surmon-china/vue-awesome-swiper/compare/v4.0.0...v4.0.1) (2020-03-20)
Expand Down
5 changes: 4 additions & 1 deletion src/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ export function getDirectiveByOptions (globalOptions?: SwiperOptions): Directive
const vueContext = context as any
let swiper: Swiper = vueContext?.[instanceName]

if (!swiper) {
// Swiper will destroy but not delete instance, when used <keep-alive>
if (!swiper || (swiper as any).destroyed) {
swiper = new Swiper(element, swiperOptions)
vueContext[instanceName] = swiper
bindSwiperEvents(swiper, emitEvent)
emitEvent(ComponentEvents.Ready, swiper)
// MARK: Reinstance when the nexttick with <keep-alive>
// Vue.nextTick(instancing) | setTimeout(instancing)
}
},
// On options changed or DOM updated
Expand Down
1 change: 1 addition & 0 deletions src/swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
this.initSwiper()
}
},
// Update swiper when the parent component activated with `keep-alive`.
activated() {
this.updateSwiper()
},
Expand Down

0 comments on commit 044629c

Please sign in to comment.