我正在将这个简单的Vue组件导入我的main.js
文件(NativeScript-Vue应用)
App.vue
<template>
<Page>
<ActionBar title="Welcome to NativeScript-Vue!"/>
<StackLayout>
<Label class="message" :text="msg" col="0" row="0" @tap="log"/>
</StackLayout>
</Page>
</template>
<script>
export default {
data() {
return {
msg: "Hello World!"
}
},
methods: {
log() {
console.log("clicked")
}
}
}
</script>
main.js
如何访问在主要Vue组件之外的App.vue
中使用的main.js
的实例。像下面这样,我将在对主要Vue组件调用firebase
方法之前初始化start()
import Vue from 'nativescript-vue'
import App from './components/App'
import * as firebase from 'nativescript-plugin-firebase'
/* how to access App component's instance here */
firebase.init().then(() => {
console.log('firebase initialized')
/* how to call log() or change msg's value here */
})
new Vue({
render: h => h('frame', [h(App)])
}).$start()
我可以通过某种方式访问导入的组件数据并在初始化Firebase时更改 msg 的值吗?
答案 0 :(得分:0)
像这样尝试:
import Vue from 'nativescript-vue'
import App from './components/App'
import * as firebase from 'nativescript-plugin-firebase'
/* how to access App component's instance here */
firebase.init().then(() => {
console.log('firebase initialized')
/* how to call log() or change msg's value here */
myApp.log()
})
const myApp = new Vue({
render: h => h('frame', [h(App)])
}).$start()
但是未经测试。