网络编程
位置:首页>> 网络编程>> JavaScript>> vue.js中toast用法及使用toast弹框的实例代码

vue.js中toast用法及使用toast弹框的实例代码

作者:新叶之扉之丹儿  发布时间:2024-05-08 09:33:02 

标签:vue.js,toast,用法

1.首先引入


import { Toast } from 'vant'

写个小列子

绑定一个click事件

vue.js中toast用法及使用toast弹框的实例代码

2.写事件

在methods写方法


showToast() {
   this.$toast({
    message: "今日签到+3",
    })
 },

3.效果图如下

vue.js中toast用法及使用toast弹框的实例代码

一个简单的toast提示成就好了

下面通过实例代码看下vue 中使用 Toast弹框


import { ToastPlugin,ConfirmPlugin,AlertPlugin} from 'vux'
Vue.use(ToastPlugin)
Vue.use(ConfirmPlugin)
Vue.use(AlertPlugin)
//公用的弹窗(全局变量)
Vue.prototype.showToast = function( showPositionValue,type,text,width="10em"){
this.$vux.toast.show({
showPositionValue: false,
text: text,
type: type,
width: width,
position: 'middle'
})
}
//公用alert confirm
const Message = {};
Message.install = () => {
const msg = {
  alert: config => {
  let def = {
   title:'提示',
   content:'系统异常,请重新登录后再试!',
   buttonText:'确定'
  }
  if(typeof config === 'string' || typeof config === 'number'){
 Vue.$vux.alert.show(Object.assign(def,{content:config}));
}else{
 Vue.$vux.alert.show(Object.assign(def,config));
}
},
confirm: config => {
 let isConfirm = false;
 let def = {
   title:'提示',
   content:'系统异常,请重新登录后再试!',
   confirmText:'确定',
   cancelText:'取消',
   onConfirm:() =>{
   isConfirm = true;
}
}
 if(typeof config === 'string' || typeof config === 'number'){
  Vue.$vux.confirm.show(Object.assign(def,{content:config}));
 }else{
  Vue.$vux.confirm.show(Object.assign(def,config));
 }
/*return new Promise((resolve,reject) => {
 if(isConfirm){
 resolve();
 }
 })*/
},
}
Object.entries(msg).forEach(([method,fn]) => {
 Vue.prototype[method] = fn;
})
}
Vue.use(Message)
//使用例子
_this.confirm({
title:'提示',
content: '确定要关闭订单',
onConfirm() {
 console.log('取消订单了');
}
});

总结

以上所述是小编给大家介绍的vue.js中toast用法及使用toast弹框的实例代码网站的支持!

来源:https://blog.csdn.net/ZXD1314520/article/details/81870563

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com