我遇到了这个问题,idk如何解决此问题! 渲染错误:
TypeError: _vm.img.loadImg is not a function.
我想用loadImg(id)
方法显示图片,该如何使用?我是Vue的新手。
代码:
import Vue from 'vue'
import AsyncComputed from 'vue-async-computed'
Vue.use(AsyncComputed)
export default {
name: "Sell",
components: {
Header
},
data() {
return {
divBar: DivBar,
iconNext: IconNext,
iconVaca: IconVaca,
iconPeso: IconPeso,
iconPreco: IconPreco,
iconLocal: IconLocal,
timelineItems: [],
errorObj: {
isSet: false
},
img: '',
}
},
computed: {
loadImg(id) {
this.$http.get(this.$api + "/midiasvenda/" + id)
.then(response => {
if (response.success != null) {
return response.success;
} else {
return Vaca
}
}).catch(error => {
return error;
})
return Vaca;
}
}
<template>
<div v-else class="container-sell">
<div v-for="item in timelineItems" :key="item.id" class="container-cow">
<div class="left-content">
<div class="flock-image">
<img :src="img.loadImg(item.id)" alt="" class="cow">
</div>
</div>
</div>
</div>
</template>
感谢帮助人员!
答案 0 :(得分:0)
以下行:
<img :src="img.loadImg(item.id)" alt="" class="cow">
实际上应该是:
<img :src="loadImg(item.id)" alt="" class="cow">
因为方法loadImg(item.id)
不属于img
数据属性。
答案 1 :(得分:0)
问题出在那一行:
<img :src="img.loadImg(item.id)" alt="" class="cow">
首先,您需要将其更改为:
<img :src="loadImg(item.id)" alt="" class="cow">
第二,您不能拥有带有参数的计算属性。您需要创建一个具有相同功能的方法。示例:
methods: {
loadImg(id) {
this.$http.get(this.$api + "/midiasvenda/" + id)
.then(response => {
if (response.success != null) {
return response.success;
} else {
return Vaca
}
}).catch(error => {
return error;
})
return Vaca;
}
}
编辑: