0

I have a simple "show" component that fetches some data via an API call and renders it on the page.

<template>
  <div class="showNote">
    <div>
      {{note.title}}
    </div>
  </div>
</template>

<script>
  import NotesAPI from '@/api/notes'
  export default {
    data() {
      return {
        note: {}
      }
    },
    async fetch() {
      let id = this.$route.params.id
      let response = await NotesAPI.fetchNote(id)
      let data = response.data
      this.note.title = data.title
    }
  }
</script>

I'm finding that the rendered template is blank even though the data has been fetched and set on the data field. I can confirm this via the Vue Inspector enter image description here

It seems like the data property is not reactive and I'd need some way to force the re-rendering of the page. But obviously this would be the wrong approach. What am I missing? Why is the component not rendering my data changes?

1

1 Answer 1

2

Try to use this.$set to set nested value of an object :

 this.$set(this.note,'title', data.title)
Sign up to request clarification or add additional context in comments.

Comments

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.