demo.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="demo-list">
  3. <h4>基本用法</h4>
  4. <div>
  5. <nut-cell :showIcon="true" :isLink="true" @click.native="textToast1('我只传了文案一个参数')">
  6. <span slot="title">
  7. <label>只传文案</label>
  8. </span>
  9. </nut-cell>
  10. <nut-cell
  11. :showIcon="true"
  12. :isLink="true"
  13. @click.native="textToast2('我传了文案和显示时长两个参数,多行文字默认居中展示',5000)"
  14. >
  15. <span slot="title">
  16. <label>设置显示时长</label>
  17. </span>
  18. </nut-cell>
  19. <nut-cell :showIcon="true" :isLink="true" @click.native="sucToast('操作成功')">
  20. <span slot="title">
  21. <label>Success</label>
  22. </span>
  23. </nut-cell>
  24. <nut-cell :showIcon="true" :isLink="true" @click.native="failToast('操作失败')">
  25. <span slot="title">
  26. <label>Fail</label>
  27. </span>
  28. </nut-cell>
  29. <nut-cell :showIcon="true" :isLink="true" @click.native="warnToast('操作警告')">
  30. <span slot="title">
  31. <label>Warn</label>
  32. </span>
  33. </nut-cell>
  34. </div>
  35. <h4>加载提示</h4>
  36. <div>
  37. <nut-cell :showIcon="true" :isLink="true" @click.native="showLoading()">
  38. <span slot="title">
  39. <label>Loading</label>
  40. </span>
  41. <span slot="desc">带文案+带透明遮罩(默认)+自动消失</span>
  42. </nut-cell>
  43. <nut-cell :showIcon="true" :isLink="true" @click.native="showLoading2()">
  44. <span slot="title">
  45. <label>Loading</label>
  46. </span>
  47. <span slot="desc">不自动消失+不带遮罩</span>
  48. </nut-cell>
  49. <nut-cell :showIcon="true" :isLink="true" @click.native="hideLoading()">
  50. <span slot="title">
  51. <label>隐藏Loading</label>
  52. </span>
  53. <span slot="desc">点击手动隐藏上面的Loading</span>
  54. </nut-cell>
  55. </div>
  56. <h4>自定义样式</h4>
  57. <div>
  58. <nut-cell :showIcon="true" :isLink="true" @click.native="cusBgToast('我修改了背景色和透明度')">
  59. <span slot="title">
  60. <label>自定义背景色和透明度</label>
  61. </span>
  62. </nut-cell>
  63. <nut-cell
  64. :showIcon="true"
  65. :isLink="true"
  66. @click.native="cusClassToast('我有一个名为 my-class 自定义class')"
  67. >
  68. <span slot="title">
  69. <label>自定义class</label>
  70. </span>
  71. </nut-cell>
  72. <nut-cell :showIcon="true" :isLink="true" @click.native="cusIconToast('自定义Icon')">
  73. <span slot="title">
  74. <label>自定义Icon</label>
  75. </span>
  76. </nut-cell>
  77. </div>
  78. <h4>不共享实例</h4>
  79. <p>如果不指定id,多个Toast默认将共享一个实例(loading类型与其他类型实例不共享),新的内容和设置将取代旧的,多个Toast不能同时出现。如果不需要共享实例,可以给其设置id。例如,以下两个栗子分别设置了不同id,它们可以同时出现。</p>
  80. <div>
  81. <nut-cell :showIcon="true" :isLink="true" @click.native="idToast1('我设置了id为123')">
  82. <span slot="title">
  83. <label>我设置了id为123</label>
  84. </span>
  85. </nut-cell>
  86. <nut-cell :showIcon="true" :isLink="true" @click.native="idToast2('我设置了id为321')">
  87. <span slot="title">
  88. <label>我设置了id为321</label>
  89. </span>
  90. </nut-cell>
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. import locale from "../../mixins/locale";
  96. import { locale as i18n } from "../../locales";
  97. export default {
  98. mixins: [locale],
  99. data() {
  100. return {};
  101. },
  102. methods: {
  103. textToast1(msg) {
  104. this.$toast.text(msg);
  105. },
  106. textToast2(msg, duration) {
  107. this.$toast.text(msg, { duration });
  108. },
  109. sucToast(msg) {
  110. this.$toast.success(msg, { duration:8000 });
  111. },
  112. failToast(msg) {
  113. this.$toast.fail(msg);
  114. },
  115. warnToast(msg) {
  116. this.$toast.warn(msg);
  117. },
  118. showLoading() {
  119. this.$toast.loading("加载中...", { duration: 3000 });
  120. },
  121. showLoading2() {
  122. if (this.loading) return;
  123. this.loading = this.$toast.loading("", { cover: false });
  124. },
  125. hideLoading() {
  126. this.loading && this.loading.hide();
  127. this.loading = null;
  128. },
  129. cusBgToast(msg) {
  130. this.$toast.text(msg, { bgColor: "rgba(50, 50, 50, 0.6)" });
  131. },
  132. cusClassToast(msg) {
  133. this.$toast.text(msg, { customClass: "my-class" });
  134. },
  135. cusIconToast(msg) {
  136. this.$toast.loading(msg, {
  137. icon:
  138. "data:image/svg+xml, %3Csvg class='icon' width='200' height='200' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill='rgb(230,230,230)' d='M626.345 121.83c0 53.151-43.08 96.23-96.23 96.23-53.146 0-96.23-43.079-96.23-96.23.004-53.15 43.084-96.23 96.23-96.23 53.145 0 96.23 43.085 96.23 96.23zm-96.23 712.167c-46.505 0-84.199 37.698-84.199 84.198s37.699 84.199 84.199 84.199 84.198-37.699 84.198-84.199-37.693-84.198-84.198-84.198zm398.187-253.84c-33.218 0-60.145-26.92-60.145-60.144 0-33.219 26.927-60.145 60.145-60.145 33.224 0 60.145 26.926 60.145 60.145-.005 33.218-26.931 60.144-60.145 60.144zm-700.145-60.144c0-53.146-43.08-96.23-96.23-96.23-53.146 0-96.23 43.08-96.23 96.23 0 53.145 43.08 96.23 96.23 96.23 53.15 0 96.23-43.085 96.23-96.23zm88.448-349.599c37.581 37.58 37.581 98.509 0 136.085-37.58 37.58-98.508 37.58-136.09 0s-37.58-98.51 0-136.09 98.51-37.58 136.09.005zm444.038 580.127c-28.186 28.185-28.186 73.881-.006 102.067 28.186 28.186 73.882 28.186 102.068 0 28.185-28.186 28.185-73.882 0-102.067-28.18-28.19-73.877-28.19-102.062 0zM845.7 272.476c-18.79 18.79-49.26 18.79-68.04 0-18.795-18.795-18.795-49.26 0-68.045a48.097 48.097 0 0 1 68.04 0c18.79 18.79 18.79 49.26 0 68.045zM316.605 733.527c-37.58-37.58-98.508-37.58-136.09 0s-37.58 98.509 0 136.085c37.582 37.58 98.51 37.58 136.085 0 37.581-37.576 37.581-98.504.005-136.085z'/%3E%3C/svg%3E",
  139. duration: 3000,
  140. loadingRotate: true
  141. });
  142. },
  143. idToast1(msg) {
  144. this.$toast.success(msg, { id: 123 });
  145. },
  146. idToast2(msg) {
  147. this.$toast.text(msg, { id: 321, duration: 4000 });
  148. }
  149. }
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. </style>