Skip to content

Commit

Permalink
fix: unmount and script tag fixes in vue2
Browse files Browse the repository at this point in the history
  • Loading branch information
ubercj committed Jun 5, 2023
1 parent 37881e9 commit 0b96387
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/vue2/src/google-translate-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default Vue.extend<
hoveredLanguageCode: '',
setTimeoutId: -1,
jsonCallbackFnName: '',
scriptTag: null,
googleTranslateOriginSelectObserve: {},
htmlAttrLangObserve: {},
ns,
Expand Down Expand Up @@ -153,8 +154,17 @@ export default Vue.extend<
},
// @ts-ignore
beforeUnmount() {
this.googleTranslateOriginSelectObserve!.stop!()
this.htmlAttrLangObserve!.stop!()
if (this.googleTranslateOriginSelectObserve?.stop) {
this.googleTranslateOriginSelectObserve!.stop!()
}
if (this.htmlAttrLangObserve?.stop) {
this.htmlAttrLangObserve!.stop!()
}
if (this.scriptTag?.unload) {
this.scriptTag.unload()
}
// eslint-disable-next-line @typescript-eslint/no-this-alias
const _this = this
Expand Down Expand Up @@ -220,7 +230,7 @@ export default Vue.extend<
createGoogleTranslate() {
this.createStyle()
this.createJsonCallback()
this.createScript()
this.scriptTag = this.createScript()
},
/**
* Triggers translations by observe changes in the DOM of GoogleTranslate's original select.
Expand Down

0 comments on commit 0b96387

Please sign in to comment.