demo.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="demo">
  3. <h2>基本用法</h2>
  4. <div>
  5. <nut-cell
  6. title="Text 文字提示"
  7. is-link
  8. @click="textToast('网络失败,请稍后再试~')"
  9. ></nut-cell>
  10. <nut-cell
  11. title="Success 成功提示"
  12. is-link
  13. @click="successToast('成功提示')"
  14. ></nut-cell>
  15. <nut-cell
  16. title="Error 失败提示"
  17. is-link
  18. @click="errorToast('失败提示')"
  19. ></nut-cell>
  20. <nut-cell
  21. title="Warning 警告提示"
  22. is-link
  23. @click="warningToast('警告提示')"
  24. ></nut-cell>
  25. </div>
  26. <h2>动态更新</h2>
  27. <nut-cell
  28. title="Loading 加载提示"
  29. is-link
  30. @click="loadingToast('加载中')"
  31. ></nut-cell>
  32. </div>
  33. </template>
  34. <script>
  35. import { getCurrentInstance } from 'vue';
  36. import { createComponent } from '@/utils/create';
  37. const { createDemo } = createComponent('toast');
  38. export default createDemo({
  39. setup() {
  40. const { proxy } = getCurrentInstance();
  41. const textToast = msg => {
  42. proxy.$toast.text(msg, { duration: 100000 });
  43. };
  44. const successToast = msg => {
  45. proxy.$toast.success(msg, { duration: 100000 });
  46. };
  47. const errorToast = msg => {
  48. proxy.$toast.fail(msg);
  49. };
  50. const warningToast = msg => {
  51. proxy.$toast.warn(msg);
  52. };
  53. const loadingToast = msg => {
  54. proxy.$toast.loading(msg, { duration: 0, id: 'test' });
  55. setTimeout(() => {
  56. proxy.$toast.success('加载完成', { id: 'test', duration: 2000 });
  57. }, 2000);
  58. };
  59. return {
  60. textToast,
  61. successToast,
  62. errorToast,
  63. warningToast,
  64. loadingToast
  65. };
  66. }
  67. });
  68. </script>
  69. <style lang="scss" scoped></style>