zoukankan      html  css  js  c++  java
  • uni-app 自定义弹窗组件、slot插槽

    alert 子控件

    <template>
    	<view class="base-container" v-if="isHidden==true">
    		<view class="content-view">
    			<view class="container-view">
    				<view class="title">
    					我是标题1
    				</view>
    				<view class="content">
    					我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容我是内容
    				</view>
    				<slot name="abc"></slot>
    				<!-- <slot></slot> -->
    				<view class="actions">
    					<button class="action-item" @click="confirm" plain  v-for="(item,index) in actions" :key="index">
    						{{item}}
    					</button>
    				</view>
    				<slot name="ccc"></slot>
    			</view>
    		</view>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				multipleSlots: true, // 在组件定义时的选项中启用多slot支持
    				isHidden: false,
    			};
    		},
    		props: {
    			show: {
    				type: Boolean,
    				default: false
    			},
    			actions: {
    				type: Array,
    				default:['取消', '确认']
    			}
    		},
    		watch: {
    			show(val) {
    				if (val == false) {
    
    				} else {
    					console.log('显示alert',this);
    					this.showAlert()
    				}
    			}
    		},
    		methods:{
    			hide(){
    				this.isHidden = false
    			},
    			showAlert(){
    				this.isHidden = true
    			},
    			confirm(){
    				this.$emit('onClick','123')
    				this.hide()
    			}
    		}
    	}
    </script>
    
    <style lang="less">
    	.base-container {
    		.mask-view {
    			position: fixed;
    			left: 0;
    			right: 0;
    			top: 0;
    			bottom: 0;
    			opacity: 0.1;
    		}
    
    		.content-view {
    			top: 0;
    			bottom: 0;
    			left: 0;
    			right: 0;
    			display: flex;
    			position: fixed;
    			color: red;
    			flex-direction: column;
    			align-items: center;
    			justify-content: center;
    			background-color: rgba(0, 0, 0, 0.3);
    
    			.container-view {
    				overflow: hidden;
    				display: flex;
    				align-items: center;
    				flex-direction: column;
    				background-color: white;
    				// margin-left: 40px;
    				// margin-right: 40px;
    				 80%;
    				//  250px;
    				// height: 250px;
    				border-radius: 8px;
    
    				.title {
    					margin-top: 20px;
    					color: #333333;
    					font-size: 40rpx;
    				}
    
    				.content {
    					margin-top: 10px;
    					margin-left: 10px;
    					margin-right: 10px;
    					color: #333333;
    					font-size: 30rpx;
    				}
    
    				.actions {
    					margin-top: 30rpx;
    					height: 80rpx;
    					 100%;
    					background-color: orange;
    					display: flex;
    					flex-direction: row;
    					justify-content: space-around;
    					align-items: center;
    
    					.action-item {
    						flex: 1;
    						height: 100%;
    						text-align: center;
    						line-height: 80rpx;
    						border-style: none;
    						border-top: 1rpx #eee solid;
    						border-right: 1rpx #eee solid;
    						background-color: white;
    						border-radius: 0;
    
    					}
    				}
    			}
    		}
    	}
    </style>
    
    

    index1 父控件使用

    	<alert 
    		:show="show" 
    		:actions="actions" 
    		@onClick="confirm"
    		>
    		<text slot="abc">12321321</text>
    		<text slot="ccc">12321321</text>
    		</alert>
    
  • 相关阅读:
    Webpack常用模块加载器Loader
    CSS动画 关键帧
    React 入门(6): 路由 React-Router
    React 入门(5): 引入JSX 研究JSX的createElement实现
    webpack标准模块 npm通用模块
    常用库的CDN引入
    使用codesandbox.io开启Web云开发
    css-loader + style-loader 模块化css
    React 入门(4): 单文件组件 CSS-Modules
    openldap主从数据同步-基于debain 9
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/13606476.html
Copyright © 2011-2022 走看看