在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ VUE獲取JSON數(shù)據(jù)問題

VUE獲取JSON數(shù)據(jù)問題

我想用vue獲取json中的conversation數(shù)組中最后一項中的content的數(shù)據(jù),但是我的方法渲染失敗了,求解。

json數(shù)據(jù)部分:

{"dialogue": [
        {
            "name":"a",
            "conversation":[
                {
                    "speaker":"a",
                    "content":"小伙子"
                },
                {
                    "speaker":"b",
                    "content":"The core idea"
                },
                {
                    "speaker": "a",
                    "content": "說的不錯"
                }
            ]
        },
        {
            "name":"c",
            "conversation":[
                {
                    "speaker":"c",
                    "content":"小伙子"
                },
                {
                    "speaker":"d",
                    "content":"The core idea"
                }
            ]
        }
]}

template部分:

<template>
    <div id="dialogue">
        <div id="chatcontent" v-for="thedialoge in dialogues">
            <div id="scriptbar">
            <!--下面這種寫法渲染失敗,什么也不顯示-->
                {{thedialoge.conversation[thedialoge.conversation.length-1].content}}
            </div>
        </div>
    </div>
</template>

如果換成{{thedialoge.conversation[thedialoge.conversation.length-1]}}
則瀏覽器顯示最后一個對象的代碼
{
"speaker": "a",
"content": "說的不錯"
}

script部分:

<script type="text/javascript">
    import axios from 'axios'
    export default{
        data() {
               return {
                 dialogues:[],
            }
        },
        created() {
            axios.get('static/data.json').then(response => 
                     (this.dialogues=response.data.dialogue)
                )
              }
    }
</script>
回答
編輯回答
笨小蛋

dialog是不是多一個s,在v for里面

2018年3月8日 01:21
編輯回答
你好胸

使用下面的方法呢?

{{thedialoge.conversation[thedialoge.conversation.length-1]['content']}}
2017年7月12日 04:04
編輯回答
司令

我試了下是可以的呀

html部分:
<div id="content">
  <template>
    <div id="dialogue">
      <div id="chatcontent" v-for="thedialoge in dialogues">
        <div id="scriptbar">
          {{thedialoge.conversation[thedialoge.conversation.length-1].content}}
        </div>
      </div>
    </div>
  </template>
</div>

js部分:
    <script src="http://dialer.cdn.cootekservice.com/web/internal/activities/js/vue.min.js"></script>
<script>
  var vue = new Vue({
    el: '#content',
    data: {
      //data
      dialogues: [
        {
          "name":"a",
          "conversation":[
            {
              "speaker":"a",
              "content":"小伙子"
            },
            {
              "speaker":"b",
              "content":"The core idea"
            },
            {
              "speaker": "a",
              "content": "說的不錯"
            }
          ]
        },
        {
          "name":"c",
          "conversation":[
            {
              "speaker":"c",
              "content":"小伙子"
            },
            {
              "speaker":"d",
              "content":"The core idea"
            }
          ]
        }
      ]
    },
    created: function created() {

    },
    mounted: function mounted() {

    },
    methods: {

    }
  });
</script>
2017年5月4日 17:33