首页 > 编程知识 正文

vue怎么传数据json,vue读取本地json文件

时间:2023-05-06 17:49:20 阅读:149909 作者:333

试图通过vue获取json转换数组的最后一项内容的数据,但使用我的方法呈现失败。 解决。

Jon数据部分:

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

{ { the dialoge.conversation [ the dialoge.conversation.length-1 ].content }

如果替换为{ { the dialoge.conversation [ the dialoge.conversation.length-1 ] }

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

{

' speaker': 'a '表示,

“content': '说得很好”

}

脚本部分:

导入轴来自'轴'

导出默认{

数据()。

return {

dialogues:[]

}

(,

created () }

axios.get(static/data.JSON ) ).then ) response=

(this.dialogues=response.data.dialogue )

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。