uniapp 自定义uni.showToast,可以修改背景色,移动端(Andriod、ios)可用

如下样式

 全局修改uni.showToast样式如下:

.uni-toast {
	background: #FFFFFF !important;
	box-shadow: 0px 0px 10px 1px rgba(0,0,0,0.1) !important;
	border-radius: 10px 10px 10px 10px !important;
	color: #111111 !important;
}

如上修改只在H5上生效,在移动端 Android、ios没有生效

因此自定义一个弹框样式

<Toast ref="toast" />
import Toast from './myToast.vue';
export default {
	components: {
		Toast
	},
},

myToast.vue

<template>
  <view class="toast" v-if="isShow">
	 <div style="padding: 5px;display: flex;flex-direction: column;align-items: center;justify-content: center; width: 111px;height: 88px;background: #FFFFFF;box-shadow: 0px 0px 10px 1px rgba(0,0,0,0.1);border-radius: 10px 10px 10px 10px;">
		 <image v-if="isSucess" style="width: 40px;height: 40px;" src="../../../../static/img/ggg.png" mode=""></image>
		 <image v-if="!isSucess" style="width: 40px;height: 40px;" src="../../../../static/img/sss.png" mode=""></image>
		 <text style="color: #111111;font-size: 16px;font-weight: bold;margin-top: 5px;width: 100px;word-break: break-all;text-align: center;">{{message}}</text>
	 </div> 
  </view>
</template>
 
<script>
export default {
  data() {
    return {
      isShow: false,
      message: '',
      timer: null,
	  isSucess:false,
    };
  },
  methods: {
    show(message,num,duration=2000) {
	  if(num == 1){
		this.isSucess = true  
	  }	else if(num == 2){
		  this.isSucess = false  
	  }
      this.message = message;
      this.isShow = true;
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.isShow = false;
      }, duration);
    }
  }
};
</script>
 
<style>
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /* padding: 10px; */
  background-color: #ffffff; /* 设置背景颜色 */
  color: #fff;
  border-radius: 10px;
  z-index: 9999;
}
</style>

如上即可

 uniapp32套精选源码截图:

关注公众号「码农园区」,回复 【uniapp源码】,即可获取全套源码下载链接
在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦之归途

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值