视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
vue.js中toast用法及使用toast弹框的实例代码
2020-11-27 22:09:16 责编:小采
文档


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弹框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

下载本文
显示全文
专题