我写了如下图所示的代码,想要把接口数据请求到前端,然后根据需要调用,但是如最后一张图所示,调用照片没实现
最后一个图,src前面应该是逗号吧
/* 这里的item就是列表循环中的某一项 */
<image class="icons" :src="getIcon(item)" mode=""></image>
------js--------
const faceIcon = require('../../static/imgs/face_icon.png')
const cryIcon = require('../../static/imgs/cry_icon.png')
<script>
export default {
data() {
return {
faceIcon,
cryIcon
}
},
methods: {
getIcon(item) {
const type = item.type
if (type === 0) {
return this.faceIcon
} else {
return this.cryIcon
} ......
// 当然如果类型过多建议使用swich或其他方法,注意:faceIcon、cryIcon都是图标文件
}
}
}
应该是this的指向有问题,在uni.request外层定义一个that
let that = this
请求晚数据赋值的时候使用that去做
that.goodsContent = xxxxx
接口返回的数据结构就是数组吗,res.data代表的是后端返回的数据结构 是不是还有一级