注: 由于此组件基于 create-api 实现,所以在使用之前,请确保自己了解过 。

    显示时间设置

    1. export default {
    2. methods: {
    3. showToastTime() {
    4. const toast = this.- createToast({
    5. time: 1000,
    6. txt: 'Toast time 1s'
    7. })
    8. toast.show()
    9. },
    10. showToastTime0() {
    11. const toast = this.- createToast({
    12. time: 0,
    13. txt: 'Toast time 0'
    14. })
    15. toast.show()
    16. toast.hide()
    17. }, 2000)
    18. }
    19. }
    20. }

    显示遮罩

    mask 设置为 true 时会显示遮罩。

    类型设置

    1. <cube-button @click="showToastType">Toast - type</cube-button>
    1. export default {
    2. methods: {
    3. showToastType() {
    4. const toast = this.$createToast({
    5. txt: 'Correct',
    6. type: 'correct'
    7. })
    8. toast.show()
    9. }
    10. }
    11. }

    事件回调

    1. export default {
    2. methods: {
    3. showToastCallbak() {
    4. const toast = this.$createToast({
    5. txt: 'Timeout',
    6. onTimeout: () => {
    7. console.log('Timeout')
    8. }
    9. toast.show()
    10. }
    11. }
    12. }

    除了设置 onTimeout 的形式,还可以通过 - events 传入事件回调。

    1. export default {
    2. methods: {
    3. showToastCallbak() {
    4. const toast = this.- createToast({
    5. txt: 'Timeout',
    6. time: 1000,
    7. - events: {
    8. timeout: () => {
    9. console.log('Timeout')
    10. }
    11. }
    12. })
    13. toast.show()
    14. }
    15. }