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;
width: 80%;
// width: 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;
width: 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>