9、微信小程序学习: wepy-com-toast的使用

小程序中并不能像H5一样直接使用alert弹出消息提示,因此可以选择使用 wx.showToast 的API进行消息提示,但是官方只支持success 和 loading 两种样式。重新写一个 toast 组件成本略高,因此考虑直接使用现成的 wepy-com-toast 组件。使用方法如下:

1 . 安装组件

npm install wepy-com-toast --save

2 .无缓存编译

wepy build --no-cache

3 .需要的组件中引入 toast 组件

<template>
 <toast />
</template> <script> import wepy from 'wepy'; import Toast from 'wepy-com-toast'; export default class Index extends wepy.page { components = { toast: Toast }; } </script> 

4 .调用

this.$invoke('toast', 'show', {
 title: '系统繁忙',
 img: 'https://yourpicture.com/sad.png', }); 


猜你喜欢

转载自blog.csdn.net/u010545480/article/details/79637685
今日推荐