### [uniapp popup常用弹窗](https://pmself.com/article/3752)
**Published:** 2024-02-29T01:00:04
**Author:** chifat
**Excerpt:** 1. 上、下、左、右、中间弹出层 2. 上方成功、失败、警告、信息 提示消息 3. confirm 对话框弹窗…
#### 1\. 上、下、左、右、中间弹出层
```
return {
type: 'center',
}
methods: {
// 显示/关闭弹出层的监听
change(e) {
console.log('当前模式:' + e.type + ',状态:' + e.show);
},
// type 取值范围:left、right、top、bottom、center
toggle(type) {
this.type = type
this.$refs.popup.open(type) // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
},
}
```
#### 2\. 上方成功、失败、警告、信息 提示消息
```
return {
msgType: 'success',
messageText: '这是一条成功提示',
}
methods: {
// type 取值范围:success、error、warn、info
messageToggle(type) {
this.msgType = type
this.messageText = `这是一条${type}消息提示`
this.$refs.message.open()
},
}
```
#### 3\. confirm 对话框弹窗
```
return {
msgType: 'success',
messageText: '这是一条成功提示',
}
methods: {
// type 取值范围:success、error、warn、info
dialogToggle(type) {
this.msgType = type
this.$refs.alertDialog.open()
},
// 确认
dialogConfirm() {
console.log('点击确认')
this.messageText = `点击确认了 ${this.msgType} 窗口`
},
// 关闭
dialogClose() {
console.log('点击关闭')
},
}
```
#### 4\. prompt 输入框弹窗
```
return {
value: '',
}
methods: {
inputDialogToggle() {
this.$refs.inputDialog.open()
},
dialogInputConfirm(val) {
uni.showLoading({
title: '3秒后会关闭'
})
setTimeout(() => {
uni.hideLoading()
console.log(val)
this.value = val
// 关闭窗口后,恢复默认内容
this.$refs.inputDialog.close()
}, 3000)
},
}
```
**Tags:** popup常用弹窗, uniapp
**Categories:** Uniapp
---