2

json data

store

filmDetails: {}
......
getFilmDetail (context, param) {
     axios.get(API.filmDetails + param.id)
      .then(response => {
        context.commit('FILM_DETAILS', response.data)
      })
      .catch(err => {
        console.log(err)
      })
  }

.vue

<template>
  <section>
    <div v-for="item in filmDetails">
      <p>{{item.summary}}</p>
    </div>
  </section>
</template>
......
export default {
  name: 'detail',
  computed: {
    ...mapState(['filmDetails'])
  },
  mounted () {
    let _id = this.$route.params.id
    this.$store.dispatch('getFilmDetail', {
     id: _id
    })
  }
}

I wanna show some message on my page, like summary, but the chrome Dev tools console the 'Error in render function: "TypeError: Cannot read property 'summary' of null" ',

I tried.

1 Answer 1

2

Set a guard to prevent render before items are fetched:

<template>
  <section v-if="filmDetails && filmDetails.length">
    <div v-for="item in filmDetails">
      <p>{{item.summary}}</p>
    </div>
  </section>
</template>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, the chrome dev tools doesn't console the error, but the page is nothing,

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.