使用Vant如何完成各種Toast提示框
Vant完成各種Toast提示框
效果展示
(1)使用前的需要安裝Vant奧。
(2)在main.js里面引入Toast
import { Toast } from 'vant'; Vue.use(Toast);
(3)在頁(yè)面使用:(根據(jù)步驟代碼可以運(yùn)行奧 Toast.vue文件)(上面截圖的,在下面代碼都有栗子奧)。
<template> ? <!-- Toast提示 --> ? <div id="toast"> ? ? <van-button plain type="primary" @click="toToast">普通文字提示</van-button> ? ? <van-button plain type="primary" @click="toLoading">加載轉(zhuǎn)圈提示</van-button> ? ? <van-button plain type="primary" @click="toSuccessTip">成功提示</van-button> ? ? <van-button plain type="primary" @click="toFailTip">失敗提示</van-button> ? ? <van-button plain type="primary" @click="toCustomIcon">自定義圖標(biāo)提示</van-button> ? ? <van-button plain type="primary" @click="toCustomImage">自定義圖片提示</van-button> ? </div> </template>
<script> ? export default { ? ? data() { ? ? ? return { ? ? ? ? msg: '' ? ? ? } ? ? }, ? ? // 引入 Toast 組件后,會(huì)自動(dòng)在 Vue 的 prototype 上掛載 $toast 方法,便于在組件內(nèi)調(diào)用。 ? ? methods: { ? ? ? // 普通文字提示 ? ? ? toToast() { ? ? ? ? this.$toast({ ? ? ? ? ? message:'我是需要提示的文字', ? ? ? ? ? position:'top' ? ? ? ? }); ? ? ? }, ? ? ? ? // 加載轉(zhuǎn)圈提示 ? ? ? toLoading() { ? ? ? ? this.$toast.loading({ ? ? ? ? ? mask: true, ? ? ? ? ? message: '加載中...' ? ? ? ? }); ? ? ? }, ? ? ? ? // 成功提示 ? ? ? toSuccessTip() { ? ? ? ? this.$toast.success({ ? ? ? ? ? message:'成功的提示文案', ? ? ? ? }) ? ? ? }, ? ? ? ? // 失敗提示 ? ? ? toFailTip() { ? ? ? ? this.$toast.fail({ ? ? ? ? ? message:'失敗的提示文案' ? ? ? ? }) ? ? ? }, ? ? ? ? // ? 自定義圖標(biāo) ? ? ? toCustomIcon() { ? ? ? ? this.$toast({ ? ? ? ? ? icon: 'star-o', // 找到自己需要的圖標(biāo) ? ? ? ? ? message: '我是提示文字' ? ? ? ? }) ? ? ? }, ? ? ? ? //自定義圖片提示 ? ? ? toCustomImage() { ? ? ? ? this.$toast({ ? ? ? ? ? icon:'https://www.baidu.com/favicon.ico', ? ? ? ? ? message:'我是提示文字' ? ? ? ? }) ? ? ? } ? ? ? }, ? ? mounted() { ? ? ? } ? } </script>
<style> </style>
(4)Toast的相關(guān)API和Options 點(diǎn)擊去查看
更新補(bǔ)充
position 里面的高度不局限與 top bottom等,也可設(shè)置數(shù)值,例如:
this.$toast({ message:'我是需要提示的文字', position:'200px' // 彈框的位置可以自己設(shè)置 });
Vant Toast用法
題外話就不多講了,這是圍繞vue.js寫(xiě)的,愛(ài)上vue.js
1.首先引入
import { Toast } from 'vant'
寫(xiě)個(gè)小列子
綁定一個(gè)click事件
2.寫(xiě)事件
在methods寫(xiě)方法
showToast() { this.$toast({ message: "今日簽到+3", }) },
3.效果圖如下
一個(gè)簡(jiǎn)單的toast提示成就好了
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue項(xiàng)目中axios如何捕捉http狀態(tài)碼為401錯(cuò)誤問(wèn)題
這篇文章主要介紹了vue項(xiàng)目中axios如何捕捉http狀態(tài)碼為401錯(cuò)誤問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03Vue 樣式切換及三元判斷樣式關(guān)聯(lián)操作
這篇文章主要介紹了Vue 樣式切換及三元判斷樣式關(guān)聯(lián)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08Vue中router.beforeEach與beforeRouteEnter的區(qū)別及說(shuō)明
這篇文章主要介紹了Vue中router.beforeEach與beforeRouteEnter的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10詳解vue數(shù)據(jù)響應(yīng)式原理之?dāng)?shù)組
這篇文章主要為大家詳細(xì)介紹了vue數(shù)據(jù)響應(yīng)式原理之?dāng)?shù)組,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-02-02Vue聲明式導(dǎo)航與編程式導(dǎo)航示例分析講解
這篇文章主要介紹了Vue中聲明式導(dǎo)航與編程式導(dǎo)航,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2022-11-11