带input框的模态框 适用vue和uniapp

最近项目中遇到需要一个带input输入框的模态框。想找一个框架中自带的,结果没有找到 都是不带输入框的

因为考虑到复用性封装成组件了
父组件调用:

<view @tap="onModalShow">调用模态框<view >

<inputM :modalData='modal' @dataInput='dataInput'></inputM>
<script>
	import inputM from "../../../components/modal/modal.vue"
	export default {
		components:{
			inputM
		},
		data() {
			return {
				modal:{
					showModal: false,
					title:'标题名称',
					text:'input提示内容'
				}
			}
		},
		methods: {
			onModalShow(){
				this.modal.showModal = true
			},
			//   组件中input中传过来的值
			dataInput(res){
				console.log(res)
			}
		}
	}

组件:
HTML部分

<template name="modal">
	<view class="modalInputBg" v-show="modalData.showModal" @tap="modalData.showModal = false">
		<view class="modalInput">
			<view class="modalDiv" @tap.stop="Bubbling">
				<view class="title">企业名称</view>
				<view class="body"><input type="text" v-model="inputVal" value="" placeholder="填写企业名称"/></view>
				<view class="bottom">
					<view class="bottomCancel" @tap.stop="modalData.showModal = false">取消</view>						
					<view class="bottomDefine" @tap.stop="onDefine">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

js部分

<script>
	export default {
		props: { //此处定义传入的参数
			modalData: {
				type: Object
			}
		},
		data() {
			return {
				inputVal: ''
			}
		},

		methods: {
			onDefine(){
				this.modalData.showModal = false
				this.$emit('dataInput', this.inputVal);
				this.inputVal = ''
			},
			Bubbling(){}
		}
	}
</script>

css样式

<style>
	.modalInputBg{
		position: fixed;
		z-index: 999;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, .2);
	}
	.modalInput{
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.modalDiv{
		width: 86%;
		height: auto;
		background-color: #FFFFFF;
		border-radius: 10rpx;
	}
	.modalInput .modalDiv .title{
		text-align: center;
		padding: 48rpx 0 0 0;
		letter-spacing: 2rpx;
		font-size: 44rpx;
	}
	.modalInput .modalDiv .body{
		width: 86%;
		height: 80rpx;
		line-height: 80rpx;
		margin: 72rpx auto;
		border: 2rpx solid #DCDEE0;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.08);
		padding: 0 3%;
		box-sizing: border-box;
		border-radius: 10rpx;
	}
	.modalInput .modalDiv .body input{
		height: 100%;
	}
	.modalInput .modalDiv .bottom{
		display: flex;
		align-items: center;
		height: 88rpx;
		border-top: 2rpx solid #DCDEE0;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.08);
	}
	.modalInput .modalDiv .bottom view{
		flex: 1;
		text-align: center;
		font-size: 30rpx;
		letter-spacing: 2rpx;
		height: 100%;
		line-height: 88rpx;
	}
	.modalInput .modalDiv .bottom .bottomCancel{
		border-right: 2rpx solid #DCDEE0;
	}
	.modalInput .modalDiv .bottom .bottomDefine{
		color: #3F83F7;
	}
</style>

效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值