一款简单的适用于pc端的vue-toast/而且匹配typescript的模式.效果是默认在屏幕的垂直居中位置.
新项目要求用typescript+vue+elementui的模式来搭建pc项目,最初踩了好多坑.
产品说提示不想用element-ui的提示. 打算用toast的形式.
因此就本身写了一个pc的toast(又能结合ts)
而后放上来和你们分享一下,javascript
最初是本身写的一个component,
后面想着之后也方便用,就试了一下以npm包传上去.
toast源码html
这款toast是基于vue使用的,因此须要在vue的大环境下去安装使用.vue
npm i easytoast-f-vue --save
//toast文案 text?: string; //持续时间(ms) duration?: number; //蒙层背景色(支持直接写色号,rgb,rgba,英文单词) background?: string; //toast背景色 toastBackground?: string; //toast文字颜色 textColor?: string; //toast文字排列(适用于当出现文字太长出现换行) textAlign?: textAlign; //toast的最大宽度(默认为400px) max?: number; //支持html输入(预留容许输入html串) content?: string;
在入口的main.js或者main.ts中,java
import myToast from 'easytoast-f-vue'; Vue.use(myToast);
而后在具体须要使用的页面中,git
//普通的文字toast this.$ftoast({ text: 'TOAST', background: 'rgba(0, 0, 0, .5)', textColor: 'pink', toastBackground: 'rgba(255, 255, 255, 1)' }) //html式的toast this.$ftoast({ text: 'TOAST', background: 'rgba(0, 0, 0, .5)', textColor: 'pink', toastBackground: 'rgba(255, 255, 255, 1)', content: '<div class="t"><p class="r">红色的字</p><p>蓝色的字</p></div>' })
普通的toastgithub
html的toast (我发现若是html的toast要使用图片资源,须要放在静态文件夹,这种固定路径的才能识别到)typescript
顺便讲讲怎么简单发npm包