0

I am trying to use Vuefire in Nuxt's fetch method. It works on initial page load, however, if you refresh the browser, it will fail with the following console error:

console error

Here is the relevant code:

  async fetch() {
    await this.$bind(
      'comments',
      this.$fireStore
        .collection('comments')
        .where('photoId', '==', this.photo.id),
      {
        wait: true
      }
    )
  },
data() {
    return {
      comments: []
    }
  },

Anyone have any tips on how I can fix this so it also works if you refresh the browser? I am probably not writing the above code correctly. Thank you!

3
  • What is this.$bind doing here? async fetch() will run server side or client side depending on the curcumstance, my guess is that this code does not work server side. Commented Sep 10, 2020 at 16:11
  • what if you move ` async fetch` to mounted? Commented Sep 29, 2020 at 16:48
  • then I will lose the whole point of Server side rendering for SEO. Commented Sep 30, 2020 at 14:53

2 Answers 2

1

You have to declare this.comments on fetch()

Now the firestore API in nuxt firestore module changed to this.$fire.firestore https://firebase.nuxtjs.org/community/migrate

Answering Sergio: this.$bind came from Vuefire

https://vuefire.vuejs.org/api/vuefire.html#bind

async fetch() {
    this.comments = await this.$bind(
      'comments',
      this.$fire.firestore
        .collection('comments')
        .where('photoId', '==', this.photo.id),
      {
        wait: true
      }
    )
  },
data() {
    return {
      comments: []
    }
  },
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know what you are trying to do with this.$bind, but I guess you can make that work this way:

data() {
  return {
    comments: []
  }
},

async fetch() {
  this.comments = await this.$fireStore
    .collection('comments')
    .where('photoId', '==', this.photo.id),
  {
    wait: true
  }
},

fetchOnServer: false

You can check an example in the Nuxt documentation.

1 Comment

Thanks. However, I need to render the comments on server side for SEO. Thus, I don't think setting false willwork for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.