【发布时间】:2020-07-14 03:51:34
【问题描述】:
我想使用 Vue 组件从 JSON 中呈现以下视图:
JSON:
{
"0": {
"title": "Title0",
"content": {
"0": {
"text": "few text here",
"image": false
}
}
},
"1": {
"title": "Title1",
"content": {
"0": {
"text": "few text here",
"image": false
},
"1": {
"text": "few text here",
"image": true,
"imagePath": "../../Assets/images.sample.png"
}
}
}
}
为了解析这些数据,我编写了以下 Vue 组件:
<template>
<div>
<section v-for="(data, index) in jsonTitle" :key="index">
<h5>{{data.title}}</h5>
<article v-for="(data, index) in jsonTitle" :key="index">
<h6>{{data.content[0].text}}</h6>
<img v-if="data.content[0].image === true" v-bind:src="data.imagepath" alt="">
</article>
</section>
</div>
</template>
<script>
import json from "@/components/json/english.json";
export default {
name: "databox",
data() {
return {
jsonTitle: json
};
}
};
</script>
我肯定在这段代码中遗漏了一些东西。我只得到第二个标题的第一个数据。请提供 Vue CLI 解决方案而不是 Vue.js,因为我是新手,还没有太多知识。
【问题讨论】:
标签: javascript json vue.js vuejs2 vue-cli