c-toast


提示框

示例

  1. <template>
  2. <view class="toast-page">
  3. <c-toast duration="{{duration}}" show="{{show}}" c-bind:show="changeShow" message="{{message}}" type="{{type}}" mask="{{mask}}"></c-toast>
  4. <button btn-style="{{btnStyle}}" text="loading toast" c-bind:onclick="showLoading"></button>
  5. <button btn-style="{{btnStyle}}" text="mask toast" c-bind:onclick="showMask"></button>
  6. <button btn-style="{{btnStyle}}" text="success toast" c-bind:onclick="showSuccess"></button>
  7. <button btn-style="{{btnStyle}}" text="warn toast" c-bind:onclick="showWarn"></button>
  8. </view>
  9. </template>
  10. <script>
  11. class Index {
  12. data = {
  13. show: false,
  14. message: '',
  15. type: 'loading',
  16. mask: false,
  17. duration: 3000,
  18. btnStyle: 'margin-bottom: 20cpx'
  19. }
  20. methods = {
  21. changeShow(e) {
  22. this.show = e.detail.value
  23. },
  24. showLoading() {
  25. this.message="loading toast"
  26. this.type="loading"
  27. this.mask = false;
  28. this.duration = 1000*3;
  29. this.show = true;
  30. },
  31. showMask() {
  32. this.message="mask toast"
  33. this.type="loading"
  34. this.mask = true;
  35. this.duration = 1000*3;
  36. this.show = true;
  37. },
  38. showSuccess() {
  39. this.message="success toast"
  40. this.type="success"
  41. this.mask = true;
  42. this.duration = 1000*3;
  43. this.show = true;
  44. },
  45. showWarn() {
  46. this.message="warn toast"
  47. this.type="warn"
  48. this.mask = true;
  49. this.duration = 1000*3;
  50. this.show = true;
  51. }
  52. }
  53. }
  54. export default new Index();
  55. </script>
  56. <style scoped>
  57. .toast-page {
  58. display: flex;
  59. flex-direction: column;
  60. align-items: center;
  61. }
  62. </style>
  63. <script cml-type="json">
  64. {
  65. "base": {
  66. "usingComponents": {
  67. "c-toast": "cml-ui/components/c-toast/c-toast"
  68. }
  69. }
  70. }
  71. </script>