当前位置: 首页 > news >正文

uniapp+vue3 随机、换一批

案例

在这里插入图片描述

代码

<view class="list"><view class="row" v-for="(item,index) in showList" :key="index"><view class="txt">{{ index + 1 }}、{{item.title}}</view><view class="arrow"><fui-icon name="arrowright" color="#6C6B6B" size="34"></fui-icon></view></view><view class="replaceBtn" @click="replaceList"><image src="/pages/userSub/static/images/replace.png" mode="aspectFill"></image>换一批</view>
</view>
<script setup>import {onLoad,onShow,onReachBottom} from '@dcloudio/uni-app'import i from '@/libs/common/index.js'import api from '@/request/api.js'import {nextTick,ref,shallowRef,reactive} from "vue";import {userStore} from '@/store/userStore.js'import {commonStore} from '@/store/commonStore.js'const user = userStore()const common = commonStore()const list = ref([])const showList = ref([]) // 新增显示用的列表const page = ref(1)const size = ref(10000)const loadState = ref(1)onShow(() => {getKeFuList()getKeFuInfo()})function getKeFuList() {api.getKeFuList({page: page.value,size: size.value,}).then(res => {if (res.code == 1) {list.value = res.data// 初始化显示三条replaceList()}})}function replaceList() {// 随机打乱数组并取前三个const shuffled = [...list.value].sort(() => Math.random() - 0.5)showList.value = shuffled.slice(0, 3)}</script>
.list {margin: 0 30rpx 16rpx;background: #FFFFFF;border-radius: 20rpx 20rpx 20rpx 20rpx;padding: 0 30rpx;.row {padding: 30rpx 0;border-bottom: 1rpx solid #E4E4E4;display: flex;justify-content: space-between;align-items: center;font-size: 30rpx;color: #3D3D3D;.txt {white-space: nowrap;text-overflow: ellipsis;overflow: hidden;width: 100%;}.arrow {flex-shrink: 0;margin-left: 15rpx;}}.replaceBtn {font-size: 28rpx;color: #606266;padding: 30rpx 0;display: flex;justify-content: center;align-items: center;image {width: 24rpx;height: 24rpx;margin-right: 10rpx;}}
}
http://www.xdnf.cn/news/568639.html

相关文章:

  • anaconda创建环境出错HTTPS
  • Captiks动捕与步态分析步态分析系统MOVIT:16μs 无线同步 + 快速校准,破解传统光电困局
  • 集成 OpenTelemetry + Grafana:实现 ABP VNext 的全链路可观测性
  • API面临哪些风险,如何做好API安全?
  • vue+threeJs 创建千色三角形宇宙
  • spring-retry
  • Pandoc3.7新特性:存在合并单元格的 HTML 表格会被保留为嵌入的 HTML 表格
  • WordPress Elementor零基础教程
  • 【Redis8】最新安装版与手动运行版
  • 电商项目-商品微服务-规格参数管理,分类与品牌管理需求分析
  • FFmpeg中使用Android Content协议打开文件设备
  • 免费的DDOS防护对网站业务有用吗?
  • 电子电路:什么是寄生电容?
  • 迅为RK3568开发板Linux_NVR_SDK系统开发编译 rootfs 提示分区小
  • 以太坊ETH创建代币完整教程
  • 2025.05.21华为暑期实习机考真题解析第一题
  • html,js获取扫码设备的输入内容
  • 自监督学习与监督学习
  • docker中使用openresty
  • 《国家职业教育平台:点亮职业教育新灯塔》
  • JMeter 教程:正则表达式提取器提取 JSON 字段数据
  • 鸿蒙HarmonyOS最新的组件间通信的装饰器与状态组件详解
  • 多模态学习笔记
  • C语言中的内存函数
  • node.js如何实现双 Token + Cookie 存储 + 无感刷新机制
  • docker exec -it abc bash
  • 【深度学习】使用Anaconda和PyTorch在无显卡Windows系统上配置强化学习环境
  • 亚马逊第四个机器人中心将如何降低30%配送成本?
  • iOS 直播技术及优化
  • Mariadb cpu 93% 问题