我想用vue获取json中的conversation数组中最后一项中的content的数据,但是我的方法渲染失败了,求解。

json数据部分:

{"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部分:

{{thedialoge.conversation[thedialoge.conversation.length-1].content}}

如果换成{{thedialoge.conversation[thedialoge.conversation.length-1]}}

则浏览器显示最后一个对象的代码

{

"speaker": "a",

"content": "说的不错"

}

script部分:

import axios from 'axios'

export default{

data() {

return {

dialogues:[],

}

},

created() {

axios.get('static/data.json').then(response =>

(this.dialogues=response.data.dialogue)

)

}

}

Logo

前往低代码交流专区

更多推荐