uniapp 自定义一个和toast一样的弹窗
要创建一个自定义的弹窗,您可以在uniapp中使用uni-modal组件。以下是一个简单的例子:
- 在您的页面中,添加一个按钮并绑定一个方法:
<template>
<view>
<button @click="showModal">显示弹窗</button>
</view>
</template>
<script>
export default {
methods: {
showModal() {
uni.showModal({
title: '提示',
content: '这是一个弹窗',
showCancel: false
})
}
}
}
</script>
- 您可以将上面的方法修改为自定义弹窗:
<template>
<view>
<button @click="showModal">显示弹窗</button>
<uni-modal ref="modal" :show="false" :title="title" :content="content" :show-cancel="false">
<view slot="buttons">
<button type="primary" @click="hideModal">确定</button>
</view>
</uni-modal>
</view>
</template>
<script>
export default {
data() {
return {
title: '提示',
content: '这是一个自定义弹窗'
}
},
methods: {
showModal() {
this.$refs.modal.show()
},
hideModal() {
this.$refs.modal.hide()
}
}
}
</script>
在上面的代码中,我们创建了一个uni-modal组件,并将其绑定到一个引用中。然后,我们在showModal方法中调用了show方法来显示弹窗。我们还提供了一个hideModal方法,使用户可以关闭弹窗。最后,我们在modal组件中添加了一个按钮,该按钮在用户单击“确定”时调用hideModal方法
原文地址: https://www.cveoy.top/t/topic/fg9T 著作权归作者所有。请勿转载和采集!