javascript - 如何为 firebase 配置 nativescript-vue 应用程序?
问题描述
我用 nativescript-vue 制作了我的第一个应用程序,并且想知道如何将 firebase 连接到我的应用程序。我的想法是从实时 Firebase 数据库中添加和读取数据。
我按照一些指南进行了以下操作:
1)我使用命令安装了firebase:“tns plugin add nativescript-plugin-firebase”。
2) 然后我从我的 firebase 项目中配置并下载了 google-services.json 文件。
这是 main.js 文件的内容。
import Vue from 'nativescript-vue'
import App from './components/App'
import firebase from 'nativescript-plugin-firebase'
import VueDevtools from 'nativescript-vue-devtools'
if(TNS_ENV !== 'production') {
Vue.use(VueDevtools)
}
// Prints Vue logs when --env.production is *NOT* set while building
Vue.config.silent = (TNS_ENV === 'production')
firebase
.init()
.then(() => console.log('Firebase initialised!'))
.catch(error => console.log(`Error: ${error}`));
new Vue({
render: h => h('frame', [h(App)])
}).$start()
这是 App.vue 文件的内容。
<template>
<Page>
<ActionBar title="App demo"/>
<GridLayout columns="*" rows="*">
<Label class="message" :text="msg" col="0" row="0"/>
</GridLayout>
<button @tap="test()">Push</button>
</Page>
</template>
<script>
import firebase from 'nativescript-plugin-firebase';
export default {
data() {
return {
msg: 'Hello World!'
}
},
methods: {
test(){
alert("click");
//FIREBASE PUSH
}
}
}
</script>
<style scoped>
ActionBar {
background-color: #1F2327;
color: #ffffff;
}
.message {
vertical-align: center;
text-align: center;
font-size: 20;
color: #333333;
}
</style>
我尝试使用此代码,但它不起作用。
firebase.push(
'/users',
{
'first': 'Eddy',
'last': 'Verbruggen',
'birthYear': 1977,
'isMale': true,
'address': {
'street': 'foostreet',
'number': 123
}
}
).then(
function (result) {
console.log("created key: " + result.key);
}
);
解决方案
推荐阅读
- react-native - 反应原生 + SAML + OKTA
- java - 如何使用 Mockito 模拟包括 EntityManager
- mysql - docker-compose mysql 导入失败 - 输入设备不是 TTY
- .net - Is there a way to put compressed file in the same folder from which it compressed the text files?
- angular - Angular 4:构建--prod:键盘事件不会触发
- stripe-payments - 条纹:将发票项目添加到发票
- php - 如何使用 PHP 在表单中提交跨度值?
- python - Pandas.query,定义一个变量
- visual-studio - 最新的 Xamarin 表单 ver3 以上错误:指定的转换无效
- wso2esb - 使用 WSO2 ESB Aggregate Mediator 的相关表达式