欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > uniapp+vue3 随机、换一批

uniapp+vue3 随机、换一批

2025/5/23 19:54:38 来源:https://blog.csdn.net/xulihua_75/article/details/148103800  浏览:    关键词: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;}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词