【问题标题】:vue.js display json datavue.js 显示 json 数据
【发布时间】:2017-09-29 16:34:16
【问题描述】:

json data

商店

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
    })
  }
}

我想在我的页面上显示一些消息,例如摘要,但是 chrome 开发工具控制台显示“渲染函数中的错误:“TypeError: Cannot read property 'summary' of null”',

我试过了。

【问题讨论】:

    标签: javascript json vue.js


    【解决方案1】:

    设置保护以防止在获取项目之前渲染:

    <template>
      <section v-if="filmDetails && filmDetails.length">
        <div v-for="item in filmDetails">
          <p>{{item.summary}}</p>
        </div>
      </section>
    </template>
    

    【讨论】:

    • 是的,chrome 开发工具没有解决错误,但是页面什么都没有,
    猜你喜欢
    • 1970-01-01
    • 2022-11-16
    • 2017-07-19
    • 2018-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2020-04-08
    相关资源
    最近更新 更多