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彈框的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com