<script>
import Firebase from 'firebase'
// Initialize Firebase
let config = {
apiKey: '....',
authDomain: '....',
databaseURL: '...',
projectId: '...',
storageBucket: '',
messagingSenderId: '...'
}
let app = Firebase.initializeApp(config)
// Reference messages collection
let db = app.database()
let messagesRef = db.ref('messages')
export default {
name: 'scopes-example',
firebase: {
messages: messagesRef
},
validator: null,
data () {
return {
form: {
name: '',
tel: '',
text: '',
email: '',
send: '',
alert: 'Сообщение отправлено!',
submit_form: 'Оправить',
errors: null
},
firebaseSave: {
name: '',
email: '',
phone: '',
message: ''
}
}
},
methods: {
validateBeforeSubmit () {
this.$validator.validateAll().then((result) => {
if (result) {
// Save messages
messagesRef.push(this.firebaseSave)
this.firebaseSave.name = ''
this.firebaseSave.email = ''
this.firebaseSave.phone = ''
this.firebaseSave.message = ''
....
}
})
}
}
}
</script>
if (!Firebase.apps.length) {
Firebase.initializeApp({})
}
vendor: [
'firebase'
],
import * as firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
var config = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: "233455844395"
};
!firebase.apps.length ? firebase.initializeApp(config) : ''
export const GoogleProvider = new firebase.auth.GoogleAuthProvider();
export const auth = firebase.auth();
export const DB = firebase.database();
export default firebase
import firebase from "firebase";
const config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
};
firebase.initializeApp(config);
const db = firebase.database();
export { db };
/*
** Plugins
*/
plugins: [
{ src: '~/plugins/firebase', ssr: false }
]
Опция ssr: false
отключает выполнение скрипта на стороне сервера
import SectionHero from '~/components/sections/Hero.vue';
import SectionAboutUs from '~/components/sections/AboutUs.vue';
import { db } from '~/plugins/firebase.js';
export default {
components: {
SectionHero,
SectionAboutUs
},
methods: {
addCar: function () {
db.ref('cars/fiat').set({
model: "Fiat Ducato",
year: 2017,
active: false
});
}
}
}
vendor: [
'firebase'
],