点击提交,提示,然后输入框输入内容了,还提示
<template>
<view>
<uni-forms ref="form" :rules="rules">
<uni-forms-item label="收件人" name="name">
<uni-easyinput type="text" v-model="formData.name" placeholder="请输入姓名" />
</uni-forms-item>
<uni-forms-item label="手机号" name="mobile">
<uni-easyinput type="text" v-model="formData.mobile" placeholder="请输入手机号" />
</uni-forms-item>
<uni-forms-item label="地址" name="address">
<uni-easyinput type="textarea" v-model="formData.address" placeholder="请输入详细地址" />
</uni-forms-item>
</uni-forms>
<button @click="submit">Submit</button>
</view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { reactive, ref } from "vue";
const form = ref(null)
const formData = reactive({
name : "",
mobile : "",
address : ""
})
const rules = reactive({
name : {
rules : [{
required: true,
errorMessage: '收件人不能为空'
}]
}
mobile : {
rules : [
{
required: true,
errorMessage: '手机号不能为空'
},
{
format: 'number',
errorMessage: '只能输入数字'
}
]
},
address : {
rules : [{
required: true,
errorMessage: '地址不能为空'
}]
}
})
//接受上个页面传递过来的参数
onLoad(function (option) {
console.log(option)
})
function submit () {
form.value.validate().then(res => {
console.log('success', res);
uni.showToast({
title: `校验通过`
})
}).catch(err => {
console.log('err', err);
})
console.log(form.value)
}
</script>