Skip to content

Commit 3df80ea

Browse files
committed
fix: destroy vue instance when page is disposed
fix nativescript-vue#339
1 parent 16ffa1c commit 3df80ea

File tree

1 file changed

+8
-27
lines changed
  • platform/nativescript/runtime/components

1 file changed

+8
-27
lines changed

platform/nativescript/runtime/components/page.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ export default {
1111
this.$slots.default
1212
)
1313
},
14-
// created() {
15-
// if (this.$router) {
16-
// // Sometimes the parent is undefined
17-
// // See https://github.com/nativescript-vue/nativescript-vue/issues/292
18-
// if (this.$vnode.parent) {
19-
// this.$vnode.parent.data.keepAlive = true
20-
// }
21-
// }
22-
// },
2314
mounted() {
2415
this.$el.nativeView[PAGE_REF] = this
2516

@@ -32,16 +23,19 @@ export default {
3223
const handler = e => {
3324
if (e.isBackNavigation) {
3425
this.$el.nativeView.off('navigatedFrom', handler)
35-
36-
// if (this.$router) {
37-
// this.$parent.$vnode.data.keepAlive = false
38-
// }
39-
4026
this.$parent.$destroy()
4127
}
4228
}
4329

4430
this.$el.nativeView.on('navigatedFrom', handler)
31+
32+
// ensure that the parent vue instance is destroyed when the
33+
// page is disposed (clearHistory: true for example)
34+
const dispose = this.$el.nativeView.disposeNativeView
35+
this.$el.nativeView.disposeNativeView = (...args) => {
36+
this.$parent.$destroy()
37+
dispose.call(this.$el.nativeView, args)
38+
}
4539
},
4640
methods: {
4741
_findParentFrame() {
@@ -54,17 +48,4 @@ export default {
5448
return frame
5549
}
5650
}
57-
// deactivated() {
58-
// if (this.$router) {
59-
// if (this._watcher) {
60-
// this._watcher.teardown()
61-
// }
62-
//
63-
// let i = this._watchers.length
64-
//
65-
// while (i--) {
66-
// this._watchers[i].teardown()
67-
// }
68-
// }
69-
// }
7051
}

0 commit comments

Comments
 (0)