【发布时间】:2021-09-21 09:31:36
【问题描述】:
我想在我的 VueJS 代码中读取 JSON 数据。
这是我的代码:
<template>
{{info}}
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
info: null
};
},
mounted(){
axios
.get('data/products.json')
.then(response => (this.info = response.data.data)),
}
</script>
我在网站上有这个:
[ { "id": "1000", "code": "1", "name": "Certificats", "description": “证书描述”,“状态”:“错误”},{“id”:“1005”,“代码”:“2”, “名称”:“Autre”,“描述”:“产品描述”,“状态”: “错误”}]
我希望能够仅调用例如 info.id 以仅打印 id 或将其用作 v-if 或 v-for 中的属性。
例如能够做这样的事情:
<div :v-for="number in info.id">
{{number}}
</div>
你知道怎么做吗?
谢谢
【问题讨论】:
标签: javascript html json vue.js vuejs3