1. axios获取本地json文件
本地json放在public文件夹中,axios直接使用,
export default {
name: 'Product',
components: {
AButton: Button,
},
data() {
return {
productList: [],
};
},
mounted() {
axios.get('/data/home.json').then((res) => {
this.productList = res.data;
});
},
};
2. template中v-for中循环
<div :key='product.title' v-for='product in productList'>
<img :src="product.image" alt="">
</div>