uniapp中自定义showToast样式

 

uni.showToast({
					title:'加载中...',
						icon:'loading',
						image:'../../static/images/qiya.gif',
						duration:7000,
						mask:false
				})

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp,可以使用uni.showToast()方法来显示一个toast提示框,但是它的样式是默认的,如果需要自定义样式,可以通过在App.vue注册一个全局组件来实现。 具体步骤如下: 1. 在App.vue注册一个全局组件,例如Toast。 ``` <template> <div class="toast-container" :class="{'show': visible}"> <div class="toast" :class="[type]"> {{ message }} </div> </div> </template> <script> export default { data() { return { visible: false, message: '', type: '' } }, methods: { show(options) { this.message = options.message || '' this.type = options.type || '' this.visible = true setTimeout(() => { this.visible = false }, options.duration || 2000) } } } </script> <style scoped> .toast-container { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999; } .toast { display: inline-block; padding: 10px 20px; border-radius: 4px; font-size: 14px; color: #fff; text-align: center; background-color: rgba(0, 0, 0, 0.7); } .toast.success { background-color: #52c41a; } .toast.warning { background-color: #faad14; } .toast.error { background-color: #f5222d; } .toast.show { opacity: 1; transition: opacity 0.3s; } .toast.hide { opacity: 0; transition: opacity 0.3s; } </style> ``` 2. 在需要显示toast的页面,通过this.$refs.toast.show()方法来调用Toast组件。 ``` <template> <view> <button @click="showToast">显示toast</button> </view> </template> <script> export default { methods: { showToast() { this.$refs.toast.show({ message: '这是一个toast提示', type: 'success', // success/warning/error duration: 3000 // 可选,单位为毫秒,默认为2000 }) } } } </script> <style> </style> ``` 以上就是在uniapp自定义toast提示框样式的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值