LoginSignup
7
5

More than 5 years have passed since last update.

vuefireでFirestoreとbindするときにハマったこと

Last updated at Posted at 2018-01-30

今回はvuefireでFirestoreをbindするときにすこし手間取ったので、それを共有したいと思います。

まず最初に結論から言うと、いままで存在していた$bindAsArray$bindAsObject関数は無くなり、$bindに統合されました。

自分の場合は下記のエラーで異変に気づき、どうしても解決できず、issue立てたら教えてくれました。

TypeError: _this.$bindAsObject is not a function

You don't need to specify anymore if it's a collection or a document 🙂 , so it's just $bind: https://github.com/vuejs/vuefire/blob/firestore/examples/index.html#L113

examplesをみてれば一発だったようです(READMEに書いて・・)。

さて、ここからは簡単なfirestore x vuefire導入編です。

使い方

vuefire@nextをインストールします

$ npm install vuefire@next --save

$bind関数でFirestoreのデータと紐付けます

this.$bind('loginUser', firestore.collection('users').doc(userId))

そもそもですが、上記の例のuserIdのように変数を使わないのであれば、シンプルに下記のように記述するのが良いと思います。

new Vue({
  data: {
    todos: [],
    currentTodo: null
  },
  firestore: {
    todos: db.collection('todos'),
    currentTodo: db.collection('todos').doc('1')
  }
})

参考リンク

7
5
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
7
5