4-15 活动组件开发 报错,跑不出 接口API 提供的图片
来源:1-1 为什么要有这么一门课,看看就知道啦

weixin_慕工程3403633
2022-05-26
是在用MySwiper组件时 用的那个 map 方法有问题吗?
下面是我Home.vue的源码:
<template>
<div class="home">
<div class="home-content">
<!-- swiper -->
<h1>234423</h1>
<my-swiper :swiperImgs="swiperData.map(item => item.icon)" :height="swiperHeight"></my-swiper> <!-- 520 activity -->
<activity>
<div class="activity-520">
<img v-for="(item, index) in activityDatas" :key='index' :src="item.icon">
</div>
</activity>
</div>
</div>
</template>
<script>
import MySwiper from '@c/swiper/MySwiper.vue'
import Activity from '@c/currency/Activity.vue'
export default {
components: {
MySwiper,
Activity
},
data: function () {
return {
swiperData: [],
swiperHeight: '184px',
activityDatas: []
}
},
created: function () {
this.initData();
},
methods: {
initData: function () {
// this.$http = axios;
this.$http.get('/swiper')
.then(data => {
console.log(data)
this.swiperData = data.list;
}).catch(err => {
console.log(err);
});
// 520 活动数据
this.$http.get('/activitys')
.then(data => {
this.activityDatas = data.list;
}).catch(err => {
console.log(err);
})
}
}
}
</script>
<style lang="scss" scoped>
@import '@css/style.scss';
.home {
width: 100%;
height: 100%;
background-color: $bgColor;
font-size: 32px;
&-content {
height: 100%;
.activity-520 {
margin-top: px2rem(-8);
border-top-left-radius: px2rem(8);
border-top-right-radius: px2rem(8);
img {
display: inline-block;
width: 33.33%
}
}
}
}
</style>
是后端API 返回的数据结构有问题吗?
写回答
2回答
-
weixin_慕工程3403633
提问者
2022-05-27
是axios 提取数据搞错了, 还有组件里的 img 标签的 :src="item.icon", 之前是 :src="item”
00 -
Sunday
2022-05-26
你好
从你的报错中来看 swiperData 应该是一个 undefined 。 你需要查看下你的数据
022022-05-27
相似问题