uni-app请求新闻接口api,渲染新闻列表

在网上找了一个免费的新闻api
http://v.juhe.cn/toutiao/index?type=top&key=3dc86b09a2ee2477a5baa80ee70fcdf5

但是一般免费的api,存在不了多久就挂掉了,前面收集的那些免费的api差不多已经挂了一半了,谨慎使用~

<template>
    <view class="page">
        <view class="uni-list">
            <view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="item in itemList">
                <view class="uni-list-cell-navigate uni-navigate-right uni-media-list ">
                    <view class="uni-media-list-logo">
                        <image v-if="showImg" :src="item.thumbnail_pic_s"></image>
                    </view>
                    <view class="uni-media-list-body">
                        <view class="uni-media-list-text-top">{{item.author_name}}</view>
                        <view class="uni-media-list-text-bottom uni-ellipsis">{{item.title}}</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                showImg: false,
                itemList: []
            }
        },
        onLoad() {
            this.getList();
            this.showImg = true;

        },
        methods: {
            getList() {
                uni.request({
                    url: '/api/toutiao/index?type=top&key=3dc86b09a2ee2477a5baa80ee70fcdf5',
                    success: (res) => {
                        console.log(res.data);
                        this.itemList = res.data.result.data;
                    }
                });
            }
        }
    }
</script>
<style>
    .title {
        padding: 20upx;
    }
    .uni-navigate-right.uni-media-list {
        height: 80px;
    }
</style>

解决接口跨域问题,若有不会可以查看:
uni-app学习笔记-请求接口跨域问题(八)
https://www.jianshu.com/p/aea58ee405b8

"devServer": {
                          "proxy": {
                              "/api": {                    
                                  "target":"http://v.juhe.cn",
                                  "changeOrigin": true,//是否跨域
                                  "secure": false,// 设置支持https协议的代理
                                   "pathRewrite":{"^/api":"/"}
                              }
                          }
                },

效果


5640239-3fa32f71f8414bf6.png
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值