找回密码
 立即注册

[uni-app] uni-app注册页面编写代码

[复制链接]
admin 发表于 前天 18:34 | 显示全部楼层 |阅读模式
uni-app注册页面编写代码
  1. <template>
  2.         <view>
  3.                 <uni-notice-bar show-icon scrollable :text="notice" />
  4.         </view>
  5.         <view class="reg-view">
  6.                 <uni-forms ref="userFormRef" :model="userForm" :label-width="80" :rules="rules">
  7.                         <uni-forms-item label="昵称" required name="nickname">
  8.                                 <uni-easyinput v-model="userForm.nickname" placeholder="请输入昵称" />
  9.                         </uni-forms-item>
  10.                         <uni-forms-item label="用户名" required name="username">
  11.                                 <uni-easyinput v-model="userForm.username" placeholder="请输入用户名" />
  12.                         </uni-forms-item>
  13.                         <uni-forms-item label="密码" required name="password">
  14.                                 <uni-easyinput type="password" v-model="userForm.password" placeholder="请输入密码" />
  15.                         </uni-forms-item>
  16.                         <uni-forms-item label="确认密码" required name="password2">
  17.                                 <uni-easyinput type="password" v-model="userForm.password2" placeholder="请再次确认密码" />
  18.                         </uni-forms-item>
  19.                         <uni-forms-item label="性别" required name="sex">
  20.                                 <uni-data-checkbox v-model="userForm.sex" :localdata="sexs" />
  21.                         </uni-forms-item>
  22.                         <uni-forms-item label="手机号码" required name="phone">
  23.                                 <uni-easyinput v-model="userForm.phone" placeholder="请输入手机号码" />
  24.                         </uni-forms-item>
  25.                         <uni-forms-item label="验证码" required name="captcha">
  26.                                 <view style="display: flex;justify-content: space-between;">
  27.                                         <view class="" style="width: 50%;">
  28.                                                 <uni-easyinput v-model="userForm.captcha" placeholder="请输入验证码" />
  29.                                         </view>
  30.                                         <view class="" style="width: 48%;">
  31.                                                 <button type="default" style="width: 99%;height: 35px;line-height: 35px;"
  32.                                                         size="mini">获取验证码</button>
  33.                                         </view>
  34.                                 </view>
  35.                         </uni-forms-item>
  36.                 </uni-forms>
  37.                 <button type="primary" class="round-button" @tap="reg">注册</button>
  38.         </view>
  39. </template>
  40. <script setup>
  41.         import {
  42.                 ref
  43.         } from 'vue';
  44.         const userFormRef = ref()
  45.         const reg = () => {
  46.                 userFormRef.value.validate().then(res => {
  47.                         console.log('验证通过:', res);
  48.                 }).catch(err => {
  49.                         console.log('表单错误信息:', err);
  50.                 })
  51.         }
  52.         const userForm = ref({})
  53.         const sexs = ref([{
  54.                 text: '男',
  55.                 value: 0
  56.         }, {
  57.                 text: '女',
  58.                 value: 1
  59.         }, {
  60.                 text: '保密',
  61.                 value: 2
  62.         }])
  63.         const notice = ref("明天放假了")
  64.         // 表单验证规则
  65.         const rules = {
  66.                 // 对name字段进行必填验证
  67.                 nickname: {
  68.                         rules: [{
  69.                                         required: true,
  70.                                         errorMessage: '请输入昵称',
  71.                                 },
  72.                                 {
  73.                                         minLength: 2,
  74.                                         maxLength: 50,
  75.                                         errorMessage: '昵称长度在 {minLength} 到 {maxLength} 个字符',
  76.                                 }
  77.                         ]
  78.                 },
  79.                 username: {
  80.                         rules: [{
  81.                                         required: true,
  82.                                         errorMessage: '请输入用户名',
  83.                                 },
  84.                                 {
  85.                                         minLength: 3,
  86.                                         maxLength: 20,
  87.                                         errorMessage: '用户名长度在 {minLength} 到 {maxLength} 个字符',
  88.                                 }
  89.                         ]
  90.                 },
  91.                 password: {
  92.                         rules: [{
  93.                                         required: true,
  94.                                         errorMessage: '请输入密码',
  95.                                 },
  96.                                 {
  97.                                         minLength: 6,
  98.                                         maxLength: 20,
  99.                                         errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
  100.                                 }
  101.                         ]
  102.                 },
  103.                 password2: {
  104.                         rules: [{
  105.                                         required: true,
  106.                                         errorMessage: '请再次确认密码',
  107.                                 },
  108.                                 {
  109.                                         minLength: 6,
  110.                                         maxLength: 20,
  111.                                         errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
  112.                                 }
  113.                         ]
  114.                 },
  115.                 sex: {
  116.                         rules: [{
  117.                                 required: true,
  118.                                 errorMessage: '请选择性别',
  119.                         }]
  120.                 },
  121.                 phone: {
  122.                         rules: [{
  123.                                         required: true,
  124.                                         errorMessage: '请输入手机号码',
  125.                                 },
  126.                                 {
  127.                                         minLength: 11,
  128.                                         maxLength: 11,
  129.                                         errorMessage: '手机号码长度为11个字符',
  130.                                 }
  131.                         ]
  132.                 },
  133.                 captcha: {
  134.                         rules: [{
  135.                                         required: true,
  136.                                         errorMessage: '请输入验证码',
  137.                                 },
  138.                                 {
  139.                                         minLength: 6,
  140.                                         maxLength: 6,
  141.                                         errorMessage: '验证码长度为6个字符',
  142.                                 }
  143.                         ]
  144.                 },
  145.         }
  146. </script>
  147. <style lang="scss">
  148.         .reg-view {
  149.                 padding: 20px;
  150.         }
  151. </style>
复制代码

QQ|网站地图|Archiver|小黑屋|金黑网络 ( 粤ICP备2021124338号 )

网站建设,微信公众号小程序制作,商城系统开发,高端系统定制,app软件开发,智能物联网开发,直播带货系统等

Powered by Www.Jinhei.Cn

Copyright © 2013-2024 深圳市金黑网络技术有限公司 版权所有

快速回复 返回顶部 返回列表