1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

firebaseの導入方法

Posted at

firebaseの導入方法

事前準備:firebaseのプロジェクトを作成する

firebaseのサイトURL:
https://firebase.google.com/?hl=ja

以下の手順でプロジェクトを作成し、ウェブアプリにfirebaseを追加する

(1)プロジェクトの作成

スクリーンショット 2023-10-15 10.49.46.png
スクリーンショット 2023-10-15 10.50.20.png
スクリーンショット 2023-10-15 10.50.42.png

(2)ウェブアプリにfirebaseを追加

スクリーンショット 2023-10-15 10.50.52.png
スクリーンショット 2023-10-15 10.50.59.png
すると以下のような内容が出てくる。これをあとで使用するためコピーしておく。

const firebaseConfig = {
  apiKey: '...',
  authDomain: '...',
  projectId: '...',
  storageBucket: '...',
  messagingSenderId: '...',
  appId: '...',
};

firebaseを導入する

ターミナルで、firebaseを使用したいディレクトリに移動

cd プロジェクト名

npm intallをする

npm install firebase@8.7.1

main.jsでimportする

import Vue from 'vue';

//firebaseの基礎部分
import firebase from 'firebase/app';

import App from './App.vue';
import './app.css';

//firebaseから取り入れたいサービス
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/storage';

Vue.config.productionTip = false;

//先ほどの「ウェブアプリにfirebaseを追加」で発行したapikeyなどをペーストする
const firebaseConfig = {
  apiKey: '...',
  authDomain: '...',
  projectId: '...',
  storageBucket: '...',
  messagingSenderId: '...',
  appId: '...',
};

firebase.initializeApp(firebaseConfig);

new Vue({
  render: (h) => h(App),
}).$mount('#app');

以上でfirebaseの導入方法は完成。
firebaseサービスのauthentication, firestore, storageについての扱い方については違う記事で紹介する。

まとめ

①firebaseのサイトからAPIキーなどを取得する。
②npmインストールして、main.jsにimportして、そこにAPIキーなどを記載すればOK

さあ早速firebaseを使ってみよう!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?