toast.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap">
  5. <view class="uni-btn-v">
  6. <button type="default" @tap="toast1Tap">点击弹出默认toast</button>
  7. <button type="default" @tap="toast2Tap">点击弹出设置duration的toast</button>
  8. <button type="default" @tap="toast3Tap">点击弹出显示loading的toast</button>
  9. <!-- #ifndef MP-ALIPAY -->
  10. <button type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
  11. <!-- #endif -->
  12. <!-- #ifdef APP-PLUS -->
  13. <button type="default" @tap="toast5Tap">点击显示无图标的居底toast</button>
  14. <!-- #endif -->
  15. <button type="default" @tap="hideToast">点击隐藏toast</button>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. title: 'toast'
  25. }
  26. },
  27. // #ifdef MP-ALIPAY
  28. onUnload() {
  29. this._showTimer && clearTimeout(this._showTimer);
  30. },
  31. // #endif
  32. methods: {
  33. toast1Tap: function () {
  34. uni.showToast({
  35. title: "默认"
  36. })
  37. },
  38. toast2Tap: function () {
  39. uni.showToast({
  40. title: "duration 3000",
  41. duration: 3000
  42. })
  43. },
  44. toast3Tap: function () {
  45. uni.showToast({
  46. title: "loading",
  47. icon: "loading",
  48. duration: 5000
  49. })
  50. // #ifdef MP-ALIPAY
  51. this._showTimer && clearTimeout(this._showTimer);
  52. this._showTimer = setTimeout(() => {
  53. this.hideToast()
  54. }, 3000)
  55. // #endif
  56. },
  57. toast4Tap: function () {
  58. uni.showToast({
  59. title: "logo",
  60. image: "../../../static/uni.png"
  61. })
  62. },
  63. // #ifdef APP-PLUS
  64. toast5Tap: function () {
  65. uni.showToast({
  66. title: "显示一段轻提示",
  67. position:'bottom'
  68. })
  69. },
  70. // #endif
  71. hideToast: function () {
  72. uni.hideToast()
  73. }
  74. }
  75. }
  76. </script>