Toast 提示
全局反馈用户操作的结果。
基础用法
可以使用 type
属性,指定 Toast 的类型。
show code
<template>
<Flex>
<Button @on-click="show = true">show toast</Button>
<Toast v-model:show="show">Toast</Toast>
</Flex>
<br />
<Flex>
<Flex>
<Button @on-click="info = true">info toast</Button>
<Toast v-model:show="info" type="info">Info Toast</Toast>
</Flex>
<Flex>
<Button @on-click="success = true">success toast</Button>
<Toast v-model:show="success" type="success">Success Toast</Toast>
</Flex>
<Flex>
<Button @on-click="warning = true">warning toast</Button>
<Toast v-model:show="warning" type="warning">Warning Toast</Toast>
</Flex>
<Flex>
<Button @on-click="error = true">error toast</Button>
<Toast v-model:show="error" type="error">Error Toast</Toast>
</Flex>
</Flex>
</template>
<script>
import { defineComponent, ref } from 'vue'
import { Flex, Button, Toast } from 'comz'
export default defineComponent({
components: {
Flex,
Button,
Toast
},
setup() {
return {
show: ref(false),
info: ref(false),
success: ref(false),
warning: ref(false),
error: ref(false)
}
}
})
</script>
延时关闭
duration
属性设置自动关闭的时长。
show code
<template>
<Flex>
<Flex inline>
<Button @on-click="show1 = true">show 3000ms</Button>
<Toast v-model:show="show1" :duration="3000">Toast 3000ms</Toast>
</Flex>
<Flex inline>
<Button @on-click="show2 = true">toast 5000ms</Button>
<Toast v-model:show="show2" :duration="5000">Toast 5000ms</Toast>
</Flex>
</Flex>
</template>
<script>
import { defineComponent, ref } from 'vue'
import { Flex, Button, Toast } from 'comz'
export default defineComponent({
components: {
Flex,
Button,
Toast
},
setup() {
return {
show1: ref(false),
show2: ref(false)
}
}
})
</script>
API
属性 Attribute
Attribute | Type | Default | Description |
---|
show | boolean | false | 是否展示 |
type | 'info' | 'success' | 'warning' | 'error' | info | 提示的类型 |
duration | number | 3000 | 持续时长(毫秒) |
插槽 Slot
Slot | Description |
---|
default | 默认插槽 |
事件 Event
Event | Type | Description |
---|
update:show | (state: boolean) => void | 监听 show 值变化 |