M
M
myskypesla2017-04-02 00:04:47
firebase
myskypesla, 2017-04-02 00:04:47

How to solve error when connecting Firebase + vuejs (nuxtjs)?

I'm using nuxtjs for a new project and decided to insert the values, the template is this:

<template>
  <div v-for="slide in slides">
    <div>{{ slide.text }}</div>
    <div>{{ slide.title }}</div>
  </div>
</template>

connecting and receiving data is implemented according to the nuxtjs manual
import axios from 'axios'

  export default {
    async data () {
      let { data } = await axios.get('https://ggproduction-f0b98.firebaseio.com/slides.json')
      return { slides: data }
    }
  }

Error 1:
[Vue warn]: data functions should return an object: https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function 
(found in <Projects> at C:\Users\user\Desktop\my-project\pages\projects.vue)

Error 2:
[Vue warn]: Property or method "slides" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in <Projects> at C:\Users\user\Desktop\my-project\pages\projects.vue)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
myskypesla, 2017-04-02
@myskypesla

in my example, it was necessary to change only async data... to async asyncData...

W
wostex, 2017-04-02
@wostex

In Nuxt.js the method is called asyncData and you do just 'data'.
data - must be a function in the component, the results of asyncData will eventually be merged with it.

data: function() {
   return {
      notAsyncData: 'hello'
      ....
   }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question