父传子,调用接口,快捷
父组件script区域
props: {}, data() { return { spikeList:[], likeList:[] }; }, watch: {}, computed: {}, methods: { http(){ let that = this; this.axios.get("http://localhost:8080/api/dataHome.json") .then((res)=>{ // console.log(res.data.data); let data = res.data.data[0] that.spikeList = data.spikeList console.log(data); that.likeList = data.likeList }) } }, created() {}, mounted() { this.http() },
父组件的template
<template>
<div class="home">
<Banner></Banner>
<Icons></Icons>
<Tabs></Tabs>
<Scroll></Scroll>
<Swiper></Swiper>
<Spike :spikeList='spikeList'></Spike>
<Like :likeList='likeList'></Like>
<Footer></Footer>
</div>
</template>
子组件里面直接for循环
props: ['spikeList'],

浙公网安备 33010602011771号