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>
相关推荐
喵喵虫11 小时前
uniapp修改封装组件失败 styleIsolation
uni-app
游戏开发爱好者81 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息1 天前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”1 天前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
局外人LZ2 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
2501_915918412 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅2 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥2 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++