<template> <!-- 新闻类列表页面 --> <view class="newsList"> <div class="publicList" v-for="item in newsData" :key="item.id" @click="checkDetail(item)"> <div class="left"> <p class="title">{{ item.title }}</p> <p>{{ item.updateTime }}</p> </div> <div class="right"> <img :src="item.coverPhotosFileList.length > 0 ? item.coverPhotosFileList[0].url : ''" alt="缩略图" class="newsImg" /> </div> </div> <!-- 暂无数据 --> <div class="noDatas" v-if="newsData.length == 0"> <img src="@/static/images/noData.png" alt="暂无数据" class="imgs" /> </div> </view> </template> <script setup name="newsList"> import { onMounted, ref } from 'vue'; import { onLoad, onShow } from '@dcloudio/uni-app'; import { articleConfigPage, knowledgeConfigPage } from '@/utils/homeApi.js'; const params = ref({}); const newsData = ref([]); // 跳转详情查看 function checkDetail(item) { uni.navigateTo({ url: `./detail?title=${params.value.title}&id=${item.id}` }); } // 获取列表数据 function getDataList() { articleConfigPage({ articleType: params.value.type, wechatMiniuserId: uni.getStorageSync('userIdXGWXMN') }).then((res) => { newsData.value = res.data; }); } // 获取列表数据 function getKnowledge() { knowledgeConfigPage({ wechatMiniuserId: uni.getStorageSync('userIdXGWXMN') }).then((res) => { newsData.value = res.data; }); } // onLoad 接受页面传递的参数 onLoad((option) => { params.value = option; //设置页面的标题栏名称 uni.setNavigationBarTitle({ title: option.title }); }); onShow(() => { if (params.value.type == 'knowledge') { // 科普知识单独接口 getKnowledge(); } else { getDataList(); } }); </script> <style lang="scss"> .newsList { padding: 20rpx; .publicList { margin-bottom: 15rpx; } } </style>