uniapp布局

记录一下表单的样式修改常见问题:

使用uv-ui组件库:

vue 复制代码
<template>
	<view style="padding: 30rpx;">
		<uv-form :model="form" :rules="rules" ref="form" label-width="100">
			<!-- 要修改ui组件库的样式一定要在form-item外面包一层,(在form-item上面加class不生效)在required-view1下面去deep 否则就deep不生效 -->
			<view class="required-view1">
				<uv-form-item label="22222" prop="username"  >
					<uv-input v-model="form.username" placeholder="请输入姓名"  inputAlign="right"/>
				</uv-form-item>
			</view>
			<view class="required-view1">
				<uv-form-item label="照片" prop="pics">
					<uv-upload 
						:fileList="fileList" 
						name="1" 
						multiple 
						:maxCount="9" 
						@afterRead="afterRead" 
						@delete="deletePic" 
						:previewFullImage="true"
					></uv-upload>
				</uv-form-item>
			</view>
			<view class="required-view1">
				<uv-form-item label="照片" prop="pics">
					<uv-upload 
						:fileList="fileList" 
						name="1" 
						multiple 
						:maxCount="9" 
						@afterRead="afterRead" 
						@delete="deletePic" 
						:previewFullImage="true"
					></uv-upload>
				</uv-form-item>
			</view>
		</uv-form >
		<uv-button @click="submit">提交</uv-button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				fileList: [],
				form: {
					username: '',
					pics: []
				},
				rules: {
					username: [{
						required: true,
						message: '此为必填字段',
						trigger: ['blur', 'change']
					}],
					pics: {
						type: 'array',
						required: true,
						message: '请上传照片',
						trigger: ['blur', 'change']
					}
				}
			};
		},
		methods: {
			submit() {
				this.$refs.form.validate().then(res => {
					uni.showToast({
						icon: 'success',
						title: '校验通过'
					})
				}).catch(errors => {
					uni.showToast({
						icon: 'error',
						title: '校验失败'
					})
				})
			},
			afterRead(e) {
				// 这里直接模拟上传成功,这里的真实逻辑参考uv-upload组件示例
				setTimeout(() => {
					this.fileList = [{
						url: 'https://via.placeholder.com/100x100.png/3c9cff'
					}, {
						url: 'https://via.placeholder.com/100x100.png/ff0000'
					}]
					this.form.pics = this.fileList;
					this.$refs.form.validateField('pics', err => {
						// 处理错误后的逻辑
					})
				})
			},
			deletePic(e) {
				this.fileList.splice(e.index, 1);
				this.$refs.form.validateField('pics', err => {
					// 处理错误后的逻辑
				})
			}
		}
	}
</script>


<style scoped lang="scss">
		.required-view1 {
			
			:deep(.uv-form-item__body__left__content > .uv-form-item__body__left__content__label){
				&::after{
					display: inline-block;
					content:"*";
					color:#f56c6c;
					line-height: 9rpx;
				}
			}
			
			:deep(.uv-upload__wrap){
				//修改水平方向布局
				flex-direction: row-reverse;
			}
			:deep(.uv-upload__button){
				margin: unset;
			}
			
		}

</style>
相关推荐
普马萨特6 小时前
uni-app x 定位踩坑实录:H5/小程序/App 统一经纬度与逆地理编码
uni-app
Geek_Vison1 天前
保险APP已经用了Flutter,还能接入小程序吗?
flutter·小程序·uni-app·mpaas·小程序容器
郑州光合科技余经理1 天前
本地生活平台搭建:跨业态用户标识怎么贯通
java·开发语言·前端·后端·uni-app·php·ai编程
2501_915909062 天前
iOS应用从开发到上架App Store的完整发布流程与步骤指南
android·ios·小程序·https·uni-app·webview
不爱说话郭德纲2 天前
从“点点点”到一键出包:我把 uni-app x Android 离线打包做成了脚本
android·前端·uni-app
snotJam2 天前
关于Uniapp的Android自定义基座使用
android·uni-app
今年下半年3 天前
【微信小程序】uni-app + Vue3 + Vite 的小程序项目实现「进入指定范围才能打卡」的考勤功能
微信小程序·uni-app·定位·考勤
郑州光合科技余经理7 天前
海外版外卖加盟:总站与分站配送规则怎么分开管
java·开发语言·前端·后端·uni-app·php·ai编程
遗憾随她而去.8 天前
uniApp跨端开发: 解决不同平台显示差异问题
uni-app
程序鉴定师11 天前
2026年深圳小程序/App开发公司技术选型指南:从架构设计到交付标准全维度评估
java·小程序·uni-app·php·objective-c