Static GitHub Issues

[2227] asyncData and hot reload

prev: Improve webpack build time
next: Why process.env.NODE_ENV is undefined?

Say I have the following Vue page file in a Nuxt app:

<template>
  <div>
    <p>{{foo.bar}}</p>
    <p>{{blah}}</p>
  </div>
</template>

<script>
  import axios from '~/plugins/axios'
  export default {
    data () {
      return {
        blah: 'abc'
      }
    },
    async asyncData ({ params }) {
      let { data } = await axios.get(`/path/to/${params.id}`)
      return {
        foo: data // data = { bar: 'fgh', baz: 'ijk' }
      }
    },
  }
</script>

This works fine with both client-side and server-side rendering. However, if I'm editing/saving the file with hot-reload I'll get an error because (I assume) foo isn't defined in the data () method and it doesn't re-call the asyncData() method on hot-reload, so this.$data.foo stays undefined.

One solution to this is to add foo to the return value of data (), but that seems wrong as it would only be used on hot-reload in dev mode, yet the object would be sent to all clients in the file.

Is there a better solution to this which enables hot-reloading to work on pages which use asyncData ()?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1957">#c1957</a>)</em></sub></div>