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

博客围绕简单业务需求展开,涉及充值金额和实收金额输入框交互。当充值金额未填写,弹出Toast提示输入有效充值金额;实收金额未填,提示输入有效实付金额;两框都填写时,弹出MessageBox询问框,并给出具体demo。

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

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;
		width: 3.5rem;
		font-size: 0.5rem;
		color: white;
		background: #449EF4;
		border-radius: 0.15rem;
	}
	
	.rechage {
		text-align: center;
		margin-top: 1rem
	}
</style>
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值