Vant2组件之使用多个toast

136 阅读1分钟
  • this.$ toast.clear()会清除所有的 toast。
  • 需要同时使用多个 toast 时需要增加,this.$toast.allowMultiple
  • 设置duration: 展示时长(ms),值为 0 时,toast 不会消失

 mounted(){
	this.$toast.allowMultiple();//重点一定要加
},
methods:{
	submit(){
          const toast1 = this.$toast.loading({
              message: '加载中 ...',
              forbidClick: true,
              loadingType: 'circular',
              duration: 0   // 一直不关闭, 需手动关闭,重点一定要加
          });
          
          getInfo().then(res => {
              toast1.clear();
          }, err => {
              toast1.clear();
          });
          
          const toast2 = this.$toast.loading({
              message: '加载中 ...',
              forbidClick: true,
              loadingType: 'circular',
              duration: 0   // 一直不关闭, 需手动关闭,重点一定要加
          });
          
          getInfo().then(res => {
              toast2.clear();
          }, err => {
              toast2.clear();
          });
    }
}