博客主页 😞
图鸟ui弹出框中form表单无法绑定验证
图鸟ui弹出框中form表单无法绑定验证

Author:

芝麻

©

Wordage:

共计 1797 字

needs:

约 1 分钟

Popular:

296 ℃

Created:

:本文最后更新于2023年04月06日,已经过了1009天没有更新,若内容或图片失效,请留言反馈
目 录

示例

    <template>
    <view>
        <tn-form :model="form" ref="uForm">
        <tn-modal v-model="show" :custom="true">
                <tn-form-item label="姓名" prop="name">
                    <tn-input v-model="form.name" />
                </tn-form-item>
                <tn-form-item label="简介" prop="intro">
                    <tn-input v-model="form.intro" />
                </tn-form-item>
                <tn-form-item label="性别" prop="sex">
                    <tn-input v-model="form.sex" type="select" />
                </tn-form-item>
            <tn-button @click="submit">提交</tn-button>
        </tn-modal>
        </tn-form>
        <tn-button @click="open">
            打开模态框
        </tn-button>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                form: {
                    name: '',
                    intro: '',
                    sex: ''
                },
                rules: {
                    name: [{
                        required: true,
                        message: '请输入姓名',
                        // 可以单个或者同时写两个触发验证方式 
                        trigger: ['change', 'blur'],
                    }],
                    intro: [{
                        min: 5,
                        message: '简介不能少于5个字',
                        trigger: 'change'
                    }]
                },
                show: false,
                title: '提示信息',
                content: '提示信息的内容',
                button: [{
                        text: '取消',
                        backgroundColor: '#E6E6E6',
                        fontColor: '#FFFFFF',
                        plain: true,
                        shape: 'round'
                    },
                    {
                        text: '确定',
                        backgroundColor: 'tn-bg-indigo',
                        fontColor: '#FFFFFF'
                    }
                ]
            }
        },
        mounted() {
            this.$nextTick(() => {
                this.$refs.uForm.setRules(this.rules);
            })
        },
        methods: {
            open() {
                this.show = true;
            },
            submit() {
                this.$nextTick(() => {
                        this.$refs.uForm.validate(valid => {
                            if (valid) {
                                console.log('验证通过');
                            } else {
                                console.log('验证失败');
                            }
                        });
                })
                }
        }
    }
</script>

解决措施

将原本拟态框和form表单掉转位置,让页面可以渲染到form表单,而且最后的效果是没有变化的

文章二维码
图鸟ui弹出框中form表单无法绑定验证
 博主关闭了当前页面的评论
博客主页 芝麻博客·单人主站 哦哈哟
萌ICP备20220001号 苏ICP备2021051187号-1 本站已运行 3 年 69 天 16 小时 24 分 自豪地使用 Typecho 建站,并搭配 MyDiary 主题 Copyright © 2022 ~ 2026. 芝麻博客·单人主站 All rights reserved.
打赏图
打赏博主
欢迎
欢迎
欢迎访问芝麻博客·单人主站
与其说是博客,不如说是错题集
搜 索
足 迹
分 类
  • 默认分类
  • 前端
  • 后端
  • 模型
  • 游戏
  • 日语
  • 博客