Toast 轻提示

Scan me!

弹出式消息提示

引入

  1. import { Toast } from 'mand-mobile'
  2. Toast.succeed('操作成功')

代码演示

纯文字

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-0">
  3. <md-button @click="showTextToast">纯文字</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showTextToast() {
  15. Toast.info('一段文字')
  16. },
  17. },
  18. }
  19. </script>
  20.  

失败

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-2">
  3. <md-button @click="showSucceedToast">失败</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showSucceedToast() {
  15. Toast.failed('操作失败')
  16. },
  17. },
  18. }
  19. </script>
  20.  

连续调用

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-3">
  3. <md-button @click="start">连续调用</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. start() {
  15. Toast.loading('载入中')
  16. setTimeout(() => {
  17. Toast.hide()
  18. setTimeout(() => {
  19. Toast.failed('载入失败')
  20. }, 10)
  21. }, 500)
  22. },
  23. },
  24. }
  25. </script>
  26.  

自定义位置

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-0">
  3. <md-button @click="showTextToast">自定义位置</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showTextToast() {
  15. Toast({
  16. content: '自定义位置',
  17. position: 'bottom',
  18. })
  19. },
  20. },
  21. }
  22. </script>
  23.  

成功

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-1">
  3. <md-button @click="showSucceedToast">成功</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showSucceedToast() {
  15. Toast.succeed('操作成功')
  16. },
  17. },
  18. }
  19. </script>
  20.  

载入

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-3">
  3. <md-button @click="showLoadingToast">载入</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showLoadingToast() {
  15. Toast.loading('载入中')
  16. setTimeout(() => {
  17. Toast.hide()
  18. }, 3000)
  19. },
  20. },
  21. }
  22. </script>
  23.  

长文字

  1. <template>
  2. <div class="md-example-child md-example-child-toast md-example-child-toast-1">
  3. <md-button @click="showToast">长文字</md-button>
  4. </div>
  5. </template>
  6. <script>
  7. import {Toast, Button} from 'mand-mobile'
  8. export default {
  9. name: 'toast-demo',
  10. components: {
  11. [Button.name]: Button,
  12. },
  13. methods: {
  14. showToast() {
  15. Toast.succeed('文字部分最多展示十二个字最多展示两行')
  16. },
  17. },
  18. }
  19. </script>
  20.  

API

Toast({content, icon, duration, position, hasMask, parentNode})

显示自定义提示

属性说明类型默认值备注
iconIcon组件图标名称String-如需自定义图标, 请查看Icon组件
content提示内容文本String--
duration显示多少毫秒后自动消失, 若为0则一直显示Number3000-
position 1.3.3+展示位置Stringcentertop/center/bottom
hasMask是否显示透明遮罩, 以此防止用户点击Booleanfalse-
parentNode组件挂载节点HTMLElementdocument.body-

Toast.info(content, duration, hasMask, parentNode)

显示纯文本提示

属性说明类型默认值
content提示内容文本String-
duration显示多少毫秒后自动消失, 若为0则一直显示Number3000
hasMask是否显示透明遮罩, 以此防止用户点击Booleanfalse
parentNode组件挂载节点HTMLElementdocument.body

Toast.succeed(content, duration, hasMask, parentNode)

显示成功提示

属性说明类型默认值
content提示内容文本String-
duration显示多少毫秒后自动消失, 若为0则一直显示Number3000
hasMask是否显示透明遮罩, 以此防止用户点击Booleanfalse
parentNode组件挂载节点HTMLElementdocument.body

Toast.failed(content, duration, hasMask, parentNode)

显示失败提示

属性说明类型默认值
content提示内容文本String-
duration显示多少毫秒后自动消失, 若为0则一直显示Number3000
hasMask是否显示透明遮罩, 以此防止用户点击Booleanfalse
parentNode组件挂载节点HTMLElementdocument.body

Toast.loading(content, duration, hasMask, parentNode)

显示载入提示

属性说明类型默认值
content提示内容文本String, Number-
duration显示多少毫秒后自动消失, 若为0则一直显示Number0
hasMask是否显示透明遮罩, 以此防止用户点击Booleantrue
parentNode组件挂载节点HTMLElementdocument.body

Toast.hide()

隐藏提示