为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
Vue.js

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

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

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

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

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

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

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;
        width: 3.5rem;
        font-size: 0.5rem;
        color: white;
        background: #449EF4;
        border-radius: 0.15rem;
    }

    .rechage {
        text-align: center;
        margin-top: 1rem
    }
</style>

原文作者:祈澈姑娘
技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,爱折腾。
坚持总结工作中遇到的技术问题,坚持记录工作中所所思所见,欢迎大家一起探讨交流。

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
Web前端工程师
手记
粉丝
1.4万
获赞与收藏
118

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消