8000 fix: nativeView accessor when $el is undefined. fixes #595 (#602) · designemail/nativescript-vue@6df1351 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6df1351

Browse files
msaelicesrigor789
authored andcommitted
fix: nativeView accessor when $el is undefined. fixes nativescript-vue#595 (nativescript-vue#602)
* chore(samples): add sample app for reproducing nativescript-vue#595 * fix: fix "TypeError: Cannot read property 'nativeView' of undefined" accessing this.$options
1 parent 45f71f4 commit 6df1351

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

platform/nativescript/runtime/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Vue.prototype.$start = function() {
7979
// Define a `nativeView` getter in every NS vue instance
8080
Object.defineProperty(Vue.prototype, 'nativeView', {
8181
get() {
82-
return this.$el.nativeView
82+
return this.$el ? this.$el.nativeView : undefined
8383
}
8484
})
8585

samples/app/595.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const Vue = require('nativescript-vue')
2+
3+
Vue.config.debug = true
4+
Vue.config.silent = false
5+
6+
Plugin = {
7+
install(Vue, name) {
8+
Vue.prototype.$name = name
9+
10+
Vue.mixin({
11+
beforeCreate: function() {
12+
setTimeout(() => {
13+
console.log('this.$options: ', this.$options)
14+
}, 5000)
15+
}
16+
})
17+
}
18+
}
19+
20+
Vue.use(Plugin, 'pluginName')
21+
22+
new Vue({
23+
data: {},
24+
template: `
25+
<Frame>
26+
<Page>
27+
<ActionBar title="Issue #595" />
28+
29+
<StackLayout>
30+
<Label text="This app should not crash in 5 seconds" />
31+
<Label text="You will see a dump of this.$options in console" />
32+
</StackLayout>
33+
</Page>
34+
</Frame>
35+
`
36+
}).$start()

0 commit comments

Comments
 (0)
0