【uni-app使用uviewUI u-popup弹窗中使用el-form表单校验报错 】

@[TOC]( uni-app使用uviewUI u-popup弹窗中使用el-form表单校验报错:Error in onReady hook: “TypeError: Cannot read properties of undefined (reading ‘setRules’)” TypeError: Cannot read properties of undefined (reading ‘setRules’) )

报错截图

onReady 报错

在这里插入图片描述

点击修改按钮报错

在这里插入图片描述

问题源代码

<u-icon name="arrow-right" size="14" color="#DADADA" @click="open()"></u-icon>

<u-popup :show="show.updatePayPWD" @close="show.updatePayPWD = false" >
	<view class="form-box">
    <u--form labelPosition="left" :model="model2" ref="form1">
		<u-form-item label="原密码" prop="oldPayPassword">
            <input v-model="oldPayPassword" :maxlength="6" class="form-item-password__input" placeholder="请输入原密码" />
		</u-form-item>
	</u--from>
	<u-button type="info" text="修改" @click="submit()"></u-button>
    </view>
</u-popup>
export default {
	data(){
		return {
			model2: {
				oldPayPassword: '',
			},
			rules: {
		        payPassword: {
		          type: 'string',
		          required: true,
		          message: '请填写支付密码',
		          trigger: ['blur', 'change'],
		    	},
		    },
		};
	},
	onReady() {
    	// 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
    	this.$refs.form1.setRules(this.rules)
  	},
  	methods: {
  		open() {
  			this.show.updatePayPWD = true
  		},
  		submit() {
  			this.$refs.form1.validate().then(res => {
				uni.$u.toast('校验通过')
			}).catch(errors => {
				uni.$u.toast('校验失败')
			})
  		},
  	}
}

正确的写法

onReady() {
    	// 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
    	// this.$refs.form1.setRules(this.rules)
},
methods: {
  		open() {
  			this.show.updatePayPWD = true
  			setTimeout(() => {
        		this.$refs.form1.setRules(this.rules)
      		}, 500)
  		},
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值