我的需求是:弹出框顶部有 title,底部有确认和取消按钮。这两部分固定,中间部分 content 的高度随自身内容会动态增长,但是它最大高度不能超过父节点 bg 的 80%,而父节点 bg 的高度也是随自身内容动态变化,但最大高度又不能超过其父 cover 的 80%

<template>
<view v-if="showHello" :class="['cover', ani]" @tap.stop="show(false)">
<view :class="['bg', 'translateCenter', ani]" @tap.stop="clear">
<view class="title">
{{title}}
</view>
<view class="content">
<slot />
</view>
<view class="btn" >
<button class="btn-item" type="default" @tap="show(false)">取消</button>
<button class="btn-item" type="primary" @tap="confirm">确定</button>
</view>
</view>
</view>
</template> <script>
export default {
name: "helloPopup",
props: {
title: {
type: String,
default: 'title',
},
},
watch: {
title(newValue, oldValue) {
console.log('title:', newValue, oldValue)
},
},
created(e) {},
data(){
return {
showHello: false,
ani: '',
}
},
methods: {
show(b){
if(b){
this.showHello = true
this.$nextTick(() => {
setTimeout(() => {
this.ani = 'ani'
}, 30)
})
}else{
this.ani = ''
this.$nextTick(() => {
setTimeout(() => {
this.showHello = false
}, 300)
})
}
},
clear(){},
confirm(){
this.$emit('confirm')
},
},
}
</script> <style>
@charset "UTF-8"; *{margin:0;padding:0}
.translateCenter{ position: absolute; left:50%; top:50%; transform:translate(-50%,-50%); }
.cover{
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 99999;
background: rgba(0, 0, 0, .4);
opacity: 0;
transition: all .3s;
}
.cover.ani{
opacity: 1;
}
.bg{
max-height: 3%;
width: 3%;
opacity: 0; transition: all .3s;
}
.bg.ani{
max-height: 80%;
width: 80%;
opacity: 1; display: flex;
flex-direction: column;
background-color: #FFFFFF; border-radius: 16upx;
padding: 24upx 24upx;
overflow: hidden;
}
.content{
width: 100%;
max-height: 80%;
overflow:auto;
}
.title{
text-align: center;
font-size: 38upx;
}
.btn{
display: flex;
flex-direction: row;
justify-content: center; align-items: center;
align-content: center; vertical-align: middle;
margin-top: 40upx;
margin-bottom: 20upx;
/* background-color: #00CE47; */
}
.btn.btn-item{
flex: auto;
max-width: 40%;
}
</style>

如此这般调用:

<template>
<view>
<button @tap="show">你敢点我吗</button> <hello-popup ref="fuck" :title="popuptitle" @confirm="onConfirm">
<block v-for="(v,index) in 10" :key="index">
<view>item {{index}}</view>
</block>
<view>
备注:备注,备注,备注,备注,备注
</view>
</hello-popup>
</view>
</template> <script>
import helloPopup from '@/components/hello-popup/hello-popup.vue' export default {
components: {
helloPopup,
},
data() {
return {
popuptitle: '',
}
},
methods: {
show(){
this.popuptitle = "hangj.cnblogs.com" this.$refs.fuck.show(true)
},
onConfirm(e){
console.log('confirmed!')
this.$refs.fuck.show(false)
},
}
}
</script> <style>
</style>

欢迎留言~

uni-app 入门小白纯徒手编写组件 hello-popup的更多相关文章

  1. Angular2入门系列教程3-多个组件,主从关系

    上一篇 Angular2项目初体验-编写自己的第一个组件 好了,前面简单介绍了Angular2的基本开发,并且写了一个非常简单的组件,这篇文章我们将要学会编写多个组件并且有主从关系 现在,假设我们要做 ...

  2. 纯Swift编写的仿“随遇”应用源码

    纯Swift编写的仿“随遇”App概述 此项目是为了巩固Swift掌握而编写的,素材均来自“随遇”官方App 用Storyboard+Xib+Autolayout的方式来实现UI部分 由于项目不复杂, ...

  3. 为Node.js编写组件的几种方式

    本文主要备忘为Node.js编写组件的三种实现:纯js实现.v8 API实现(同步&异步).借助swig框架实现. 关键字:Node.js.C++.v8.swig.异步.回调. 简介 首先介绍 ...

  4. 纯代码编写qt登录界面(转)

    1. 新建Qt Widgets Application,项目名称为login1,在类信息页面保持类名和基类为MainWindow和QMainWindow不变,取消选择创建界面选项,如下图所示.     ...

  5. Jmeter Web 性能测试入门 (三):Jmeter 常用组件说明

    线程组:用来设置并发的数量和模式.是用来模拟用户并发的组件.JMeter 的每个任务都是用线程来处理的. 线程数:要并发的请求数量. Ramp-Up Period: 在多次时间内把这些并发的请求发送完 ...

  6. vue3.0入门(四):组件

    组件 组件基础 <my-counter></my-counter> const app = Vue.createApp({ // 根组件 data() { return {} ...

  7. electron 入门小白贴

    electron 入门小白贴 electron demo 跑起来! 毕设准备是做个 跨平台的做题的客户端,打算用 electron 来弄. 然而今天折腾了半天才终于吧demo给跑起来了.经历了许多的问 ...

  8. Bootstrap入门(二十一)组件15:警告框

    Bootstrap入门(二十一)组件15:警告框 通过这些简单.灵活的进度条,为当前工作流程或动作提供实时反馈. 进度条组件使用了 CSS3 的 transition 和 animation 属性来完 ...

  9. Bootstrap入门(二十)组件14:警告框

    Bootstrap入门(二十)组件14:警告框 警告框组件通过提供一些灵活的预定义消息,为常见的用户动作提供反馈消息,提示.通知或者警示,可以迅速吸引注意力. 1.情景警告框 2.可关闭的警告框 3. ...

随机推荐

  1. HCNA Routing&Switching之OSPF缺省路由发布

    前文我们了解了OSPF的度量值,以及基础配置命令的总结,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15069632.html:今天我们来聊一聊在ospf里动 ...

  2. Supervisord 远程命令执行漏洞(CVE-2017-11610)

    漏洞影响范围: Supervisor version 3.1.2至Supervisor version 3.3.2 poc 地址.https://github.com/vulhub/vulhub/tr ...

  3. Mariadb常用管理操作

    一 Mariadb常用管理操作 纯干货,没有一点废话,全是使用频率最高和常用的操作,运维必不可少的基础资料. 1.1 创建数据库 >create database <db_name> ...

  4. Python爬虫+可视化教学:爬取分析宠物猫咪交易数据

    前言 各位,七夕快到了,想好要送什么礼物了吗? 昨天有朋友私信我,问我能用Python分析下网上小猫咪的数据,是想要送一只给女朋友,当做礼物. Python从零基础入门到实战系统教程.源码.视频 网上 ...

  5. Adaptive AUTOSAR 学习笔记 12 - 通信管理

    本系列学习笔记基于 AUTOSAR Adaptive Platform 官方文档 R20-11 版本 AUTOSAR_EXP_PlatformDesign.pdf 缩写 CM:Communicatio ...

  6. python中单例模式的创建

    # 单例模式(使用装饰器) def singleton(cls): instance = {} def wrapper(*args,**kwargs): if cls not in instance: ...

  7. Android达到什么水平才能顺利拿到 20k 无压力?

    程序员分很多种类和等级,如果要提高达到20k的概率,有两个条件如果满足的话,则很容易达到: 1.一线城市:北上广深杭 2.互联网行业 如果你非得抬杠,我要在三线城市,做外包要赚20k的话,很难,我自己 ...

  8. SpringBoot报错:Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

    Spring Boot报错:Error starting ApplicationContext. To display the conditions report re-run your applic ...

  9. 树莓派SG90舵机接法

    我的舵机的三条线是红的.黑色.棕色,接法如下: 棕 : GND 红 : VCC 黄: 信号线 如图所示: 图片来源 如上图所示,写代码时注意舵机的BCM编码是18,而不是物理引脚的编码12.

  10. Notes about "Exploring Expect"

    Chapter 3 Section "The expect Command": expect_out(0,string) can NOT be written as "e ...