uni-app 之 获取网络列表数据

uni-app 之 获取网络列表数据

image.png

<template>
    <!-- vue2的<template>里必须要有一个盒子,不能有两个,这里的盒子就是 view-->
    <view>

        --- uni.request 网络请求API接口 ---
        <view v-for="(item) in caturl" :key="item.id">
            <!-- 免费的测试接口 -->
            <image :src="item.url" mode="aspectFill"></image>

            <view>{{item.id}}</view>
        </view>

    </view>
</template>

<script>
    export default {
        data() {
            return {

                caturl: [],

            }
        },
        methods: {
            getpicurl() {
                uni.showLoading({
                    title: "加载中" // 加个进度条
                })

                uni.request({
                    url: "https://api.thecatapi.com/v1/images/search?limit=2",
                    // timeout:"6000",
                    success: res => {
                        console.log(res) // log打印获取的数据
                        this.caturl = res.data
                        // this.catid = res.data.id
                        // uni.hideLoading() // 图片加载出来后,关闭进度条
                    },
                    // fail:err=>{

                    // },
                    complete: () => {
                        // 接口调用结束的回调函数(调用成功、失败都会执行) 接口调用结束的回调函数(调用成功、失败都会执行)    
                        uni.hideLoading() // 无论图片能否加载出来,超时后都关闭进度条
                    },
                    
                })
            },

        },
        onLoad() {
            
            this.getpicurl()

        }
    }
</script>

<style lang="scss">
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值