uni-app image组件在h5循环下请求2次的问题
uni-app image组件在h5循环下请求2次的问题
| 属性 | 值 |
|---|---|
| PC开发环境操作系统 | Mac |
| PC开发环境操作系统版本号 | 12 |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 3.3.10 |
| 浏览器平台 | Chrome |
| 浏览器版本 | 97 |
| 项目创建方式 | HBuilderX |
示例代码:
data(){
return {list:[]}}
mounted(){
ajax().then((data)=>{
this.list=data.list;})
}
操作步骤:
<view v-for="(item,index) in list" :key="index"><image :src="item.url"></image></view>
更多关于uni-app image组件在h5循环下请求2次的问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
10 回复
你写过请求以后,他打印两次请求,还是渲染两次
更多关于uni-app image组件在h5循环下请求2次的问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
找个最简单的demo附件一下,如果能复现到问题,请把demo发一下
mounted执行一次,image 的src会请求2次
这个一般不存在的,你的ajax方法是怎么来的
就是uni.request的封装,这个也是执行了一次
复现的demo附上来吧,老哥
<test baseUrl="http://xxx.com"></test>
<template>
<view>
<view v-for="(item,index) in list" :key="index">
<image :src="item.url">
</image>
</view>
</view>
</template>
<script>
export default {
name: "test",
props: {
baseUrl: {
type: String,
default: '',
},
},
data() {
return {
list: [],
//meta: {},
loadCount: 0,
show: false,
};
},
mounted() {
console.log('mounted')
this.getData({
page: 1
});
},
methods: {
getData(params) {
//params.pageSize = this.pageSize;
uni.$u.http.get(this.baseUrl).then((data) => {
let list = data.data.data;
this.list = list;
console.log('list')
});
},
},
}
</script>还是不知道原因
估计是image 生成的html 又一个view background url一个image src,所以是请求2次。
因为开发下,我的f12默认 disabled cache。
如果关闭disable cache 就是请求一次了。
结帖

