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

uniApp实战五:自定义组件实现便捷选择

文章目录

  • 1.最终效果预览
  • 2.快速选择组件封装
  • 3.弹框组件封装
  • 4.组件逻辑实现
  • 5.组件样式
  • 6.页面引入

1.最终效果预览

QQ_1752218066233

QQ_1752218119422

QQ_1752218139510

2.快速选择组件封装

<uv-cell :border="isShowBorder"><template v-slot:title><text class="title-key">{{ title }}</text></template><template v-slot:label><text style="font-size: 28rpx;color: #999;">{{content}}</text></template><template v-slot:value><view class="content"><view class="content-tag" v-for="(item, index) in showList" :key="index"><uv-tags :text="item.name" :plain="!item.checked" :name="index" shape="circle"@click="handleTagClick(index)"></uv-tags></view></view></template><template v-slot:right-icon><view class="content-tag" v-if="showList.length < list.length"><uv-icon size="30rpx" name="arrow-right" @click="showMoreOptions"></uv-icon></view></template></uv-cell>

基于 uv-ui 的行组件实现的快速选择,默认展示前三个值

3.弹框组件封装

<uv-popup ref="showPopup" mode="top"><view class="popup-content"><view class="popup-title">请选择</view><uv-radio-group v-model="selectedIndex" @change="handleRadioChange"><view v-for="(item, index) in list" :key="index" style="margin-right: 10px;"><uv-radio :name="index">{{ item.name }}</uv-radio></view></uv-radio-group><view class="popup-actions"><uv-button type="primary" @click="confirmSelection">确定</uv-button><uv-button @click="closePopup">取消</uv-button></view></view></uv-popup>

这两个放一个页面了,没必要再单独封装一个弹框组件了

4.组件逻辑实现

import {defineProps,defineEmits,computed,ref} from 'vue'const props = defineProps({isShowBorder: {type: Boolean,required: true},title: {type: String,required: true},content: {type: String,required: true},list: {type: Array,required: true},maxShow: {type: Number,default: 3}})const emit = defineEmits(['tagClick', 'tagMoreClick', 'selectionConfirmed'])const showList = computed(() => {return props.list.slice(0, props.maxShow)})const allList = computed(() => {return props.list})const handleTagClick = (index) => {emit('tagClick', index)}const handleMoreClick = () => {emit('tagMoreClick')}const showPopup = ref()const selectedIndex = ref({})const showMoreOptions = () => {showPopup.value.open()}const handleRadioChange = (index) => {selectedIndex.value = index}const confirmSelection = () => {emit('selectionConfirmed', selectedIndex.value)closePopup()}const closePopup = () => {showPopup.value.close()}

5.组件样式

.title-key {width: 150rpx;}.content {display: flex;flex-wrap: wrap;}.content-tag {margin: 0 0 10rpx 10rpx;}.popup-content {padding: 20rpx;}.popup-title {font-size: 32rpx;font-weight: bold;margin-bottom: 20rpx;}.popup-actions {display: flex;justify-content: space-evenly;margin-top: 20rpx;}

6.页面引入

import RowSel from '@/components/rowSel.vue'<RowSel :isShowBorder="true" :title="'维修大类'" :content="largeContent" :list="wxLargeAllList"@tagClick="radio1Click" @selectionConfirmed="tagMore1Click">
</RowSel>
<RowSel :title="'维修小类'" :content="smallContent" :list="wxSmallAllList" @tagClick="radio2Click"@selectionConfirmed="tagMore2Click">
</RowSel>const radio1Click = (index) => {}const radio2Click = (index) => {}const tagMore1Click = (index) => {radio1Click(index)}const tagMore2Click = (index) => {radio2Click(index)}

在点击事件中实现自己的逻辑选择即可

http://www.xdnf.cn/news/1100539.html

相关文章:

  • Hadoop 用户入门指南:驾驭大数据的力量
  • 如何将文件从OPPO手机传输到电脑
  • crmeb多门店对接拉卡拉支付小程序聚合收银台集成全流程详解
  • UniApp 生命周期详解:从启动到销毁的完整指南
  • WHQL认证失败怎么办?企业如何高效申请
  • 前端开发—全栈开发
  • Python中类静态方法:@classmethod/@staticmethod详解和实战示例
  • Linux:多线程---同步生产者消费者模型
  • 人事系统选型与应用全攻略:从痛点解决到效率跃升的实战指南
  • 区块链应用场景深度解读:金融领域的革新与突破
  • 资源分享-FPS, 矩阵, 骨骼, 绘制, 自瞄, U3D, UE4逆向辅助实战视频教程
  • 将Blender、Three.js与Cesium集成构建物联网3D可视化系统
  • 【SpringAI】6.向量检索(redis)
  • javaweb之相关jar包和前端包下载。
  • PHY模式,slave master怎么区分
  • 7.11文件和异常
  • 什么是进程、什么是线程(进程、线程的全方面解析)
  • 界面组件DevExpress WPF中文教程:Grid - 如何检查节点?
  • 在 React Three Fiber 中实现 3D 模型点击扩散波效果
  • JavaWeb笔记二
  • 企业级配置:Azure 邮件与 Cloudflare 域名解析的安全验证落地详解
  • CReFT-CAD 笔记 带标注工程图dxf,png数据集
  • JVM 内存结构
  • 每天一个前端小知识 Day 29 - WebGL / WebGPU 数据可视化引擎设计与实践
  • 人工智能-基础篇-29-什么是低代码平台?
  • AI问答之手机相机专业拍照模式的主要几个参数解释
  • 人工智能-基础篇-28-模型上下文协议--MCP请求示例(JSON格式,客户端代码,服务端代码等示例)
  • 大数据学习7:Azkaban调度器
  • 《Effective Python》第十三章 测试与调试——使用 Mock 测试具有复杂依赖的代码
  • Three.js+Shader实现三维波动粒子幕特效