当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue.js中toast用法及使用toast弹框的实例代码

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

2019年06月03日  | 移动技术网IT编程  | 我要评论

告别晕船,崔洪万 敖日格勒,手机快播无法播放

1.首先引入

import { toast } from 'vant'

写个小列子

绑定一个click事件

2.写事件

在methods写方法

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

3.效果图如下

一个简单的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弹框的实例代码,希望对大家有所帮助

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网