• vue.js提交按钮时简单的if判断表达式示例


    简单的业务需求如下,看图说话

    1:当充值金额没有填写的时候,会有Toast小弹框提示“请输入有效的充值金额”

    if (!this.money)
                    {
                        console.log('money',money);
                        Toast({
                            message: '请输入有效的充值金额',
                            duration: 2000
                        });
                    }
    

    2:当第二个框实收金额没有填写的时候,会有Toast小弹框提示“请输入有效的实付金额”

     else if (!this.moneyReal)
                    {
                        console.log('moneyReal',moneyReal);
                        Toast({
                            message: '请输入有效的实付金额',
                            duration: 2000
                        });
                    }
    

    3:当两个输入框都填写的时候,会弹出一个MessageBox询问框

    else
                    {
                        MessageBox.confirm('你确定要充值么?', '提示').then(action => {
                        });
                    }
    
    

    具体demo如下

    <template>
        <div class="app">
    
            <mt-field label="充值金额" id="money" placeholder="请输入" v-model="money" type="number"></mt-field>
            <mt-field label="实收金额" id="moneyReal" placeholder="请输入" v-model="moneyReal" type="number"></mt-field>
            <div class="rechage">
                <button @click="chongZhiForMember">充 值</button>
            </div>
        </div>
    </template>
    
    <script>
        import { Field, MessageBox, Toast } from 'mint-ui';
        export default {
            data() {
                return {
    
                    // 会员卡余额
                }
            },
            methods: {
    
                chongZhiForMember() {
                    if(!this.money) {
                        console.log('money', money);
                        Toast({
                            message: '请输入有效的充值金额',
                            duration: 2000
                        });
                    } else if(!this.moneyReal) {
                        console.log('moneyReal', moneyReal);
                        Toast({
                            message: '请输入有效的实付金额',
                            duration: 2000
                        });
                    } else {
                        MessageBox.confirm('你确定要充值么?', '提示').then(action => {
    
                        });
                    }
                }
            },
    
        }
    </script>
    <style scoped>
        .app {
            background: #F1F1F1;
            height: 17.78rem;
        }
        
        .rechage button {
            outline: none;
            border: none;
            height: 1rem;
             3.5rem;
            font-size: 0.5rem;
            color: white;
            background: #449EF4;
            border-radius: 0.15rem;
        }
        
        .rechage {
            text-align: center;
            margin-top: 1rem
        }
    </style>
    
  • 相关阅读:
    在MYSQL中插入当前时间,就象SQLSERVER的GETDATE()一样,以及对mysql中的时间日期操作。
    mysql使用default来设置字段的默认值
    MySQL关于check约束无效的解决办法
    C# 加密算法汇总
    REST,Web 服务,REST-ful 服务
    C# HTML 生成 PDF
    SQL Server Connection Pooling (ADO.NET)
    ADO.NET Connection Pooling at a Glance
    正则表达式
    开发 ASP.NET vNext 初步总结(使用Visual Studio 2015 Preview )
  • 原文地址:https://www.cnblogs.com/wangting888/p/9701369.html
Copyright © 2020-2023  润新知