注: 由于此组件基于 create-api 实现,所以在使用之前,请确保自己了解过 。
显示时间设置
export default {
methods: {
showToastTime() {
const toast = this.- createToast({
time: 1000,
txt: 'Toast time 1s'
})
toast.show()
},
showToastTime0() {
const toast = this.- createToast({
time: 0,
txt: 'Toast time 0'
})
toast.show()
toast.hide()
}, 2000)
}
}
}
显示遮罩
mask 设置为 true 时会显示遮罩。
类型设置
<cube-button @click="showToastType">Toast - type</cube-button>
export default {
methods: {
showToastType() {
const toast = this.$createToast({
txt: 'Correct',
type: 'correct'
})
toast.show()
}
}
}
事件回调
export default {
methods: {
showToastCallbak() {
const toast = this.$createToast({
txt: 'Timeout',
onTimeout: () => {
console.log('Timeout')
}
toast.show()
}
}
}
除了设置 onTimeout 的形式,还可以通过 - events 传入事件回调。
export default {
methods: {
showToastCallbak() {
const toast = this.- createToast({
txt: 'Timeout',
time: 1000,
- events: {
timeout: () => {
console.log('Timeout')
}
}
})
toast.show()
}
}