uniapp-form表单

javascript 复制代码
<template>
	<view class="ptb-20 plr-30 bg min100">
		<view class="bg-white radius-20 pd-30">
			<view class="bold mt-30 mb-50 size-32">选择方式:</view>
			<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
				<u-form-item label="题量" prop="number" @click="showPop(1)">
					<u--input v-model="form.number" disabled disabledColor="#ffffff" placeholder="请选择做题数量"
						border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="模式" prop="mode" @click="showPop(2)">
					<u--input v-model="form.mode" disabled disabledColor="#ffffff" placeholder="请选择做题模式" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-form-item label="排序" prop="order">
					<u-radio-group v-model="form.order" placement="row">
						<u-radio class="mr-20" label="顺序" name='0'></u-radio>
						<u-radio label="降序" name='1'></u-radio>
					</u-radio-group>
				</u-form-item>
			</u--form>
			<u-action-sheet :show="show" :actions="actions" title="请选择" @close="close" @select="confirmSelect">
			</u-action-sheet>

			<view class="flex mt-120">
				<u-button @click="back" class="mr-120" text="返回主页"></u-button>
				<u-button @click="toAnswer" type="primary" text="开始练习"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				type: null, // 1数量 2模式
				form: {
					number: '',
					mode: '',
					order: '0'
				},
				actions: [],
				rules: {
					'number': {
						type: 'number',
						required: true,
						message: '请选择做题数量',
						trigger: ['blur', 'change']
					},
					'mode': {
						type: 'string',
						required: true,
						message: '请选择做题模式',
						trigger: ['blur', 'change']
					},
				},
			};
		},
		methods: {
			showPop(type) {
				this.type = type
				this.show = true
				if (type == 1) {
					this.actions = [{
							name: 5,
						},
						{
							name: 10,
						},
						{
							name: 15,
						}, {
							name: 20,
						},
					]
				} else {
					this.actions = [{
							name: '题目难度',
						},
						{
							name: '做错时间',
						},
						{
							name: '随机',
						},
					]
				}
			},
			close() {
				this.show = false
				this.type = null
			},
			confirmSelect(e) {
				this.form[this.type == 1 ? 'number' : 'mode'] = e.name
				this.$refs.uForm.validateField(this.type == 1 ? 'number' : 'mode')
			},
			toAnswer() {
				this.$refs.uForm.validate().then(res => {
					uni.navigateTo({
						url: "/pages/subject/answerItem?type=3&query=" + encodeURIComponent(JSON.stringify(this.form))
					})
				}).catch(errors => {})

			},
			back() {
				uni.navigateBack()
			},
		},
		onReady() {
			//如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
	};
</script>
相关推荐
为风而战1 小时前
uni-app X APP在线升级 解决【uni-upgrade-center-app】未配置uni-upgrade-center 问题
uni-app
雪碧聊技术5 小时前
uniapp如何创建并使用组件?组件通过Props如何进行数据传递?
uni-app·创建组件·使用组件·props数据传递
@Dream_Chaser5 小时前
uniapp页面间通信
uni-app
@Dream_Chaser10 小时前
uniapp ruoyi-app 中使用checkbox 无法选中问题
前端·javascript·uni-app
鱼是一只鱼啊10 小时前
uniapp移动端地图提示鉴权失败请传入正确的key问题处理
uni-app
毛毛三由10 小时前
基于svga+uniapp的微信小程序动画组件开发指南
微信小程序·uni-app·notepad++
雪碧聊技术12 小时前
uniapp简介
uni-app·hbuilder
一只一只妖12 小时前
uniapp小程序无感刷新token
前端·小程序·uni-app
y东施效颦16 小时前
uni-app uni-push 2.0推送图标不展示问题
uni-app·github
初晨未凉17 小时前
uniapp返回webview返回小程序并且跳转回webview
小程序·uni-app