mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-12 12:25:16 +08:00
44 lines
1019 B
Markdown
44 lines
1019 B
Markdown
|
# 持续时间
|
||
|
自动关闭。
|
||
|
```html
|
||
|
<n-button @click="notify('info')">
|
||
|
持续时间 10000ms
|
||
|
</n-button>
|
||
|
```
|
||
|
```js
|
||
|
export default {
|
||
|
methods: {
|
||
|
notify (type) {
|
||
|
let count = 10
|
||
|
const notification = this.$NNotification.open({
|
||
|
title: `平山道 + 雨 = 什么?`,
|
||
|
content: `你有 ${count} 秒来回答这个问题`,
|
||
|
duration: 10000,
|
||
|
closable: false,
|
||
|
onAfterShow: () => {
|
||
|
const minusCount = () => {
|
||
|
count--
|
||
|
notification.content = `你有 ${count} 秒来回答这个问题`
|
||
|
if (count > 0) {
|
||
|
window.setTimeout(minusCount, 1000)
|
||
|
}
|
||
|
}
|
||
|
window.setTimeout(minusCount, 1000)
|
||
|
},
|
||
|
onAfterHide: () => {
|
||
|
this.$NNotification.open({
|
||
|
title: `答案是平山河`,
|
||
|
content: '这其实连个冷笑话都算不上',
|
||
|
duration: 10000
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
```css
|
||
|
.n-button {
|
||
|
margin: 0 12px 8px 0;
|
||
|
}
|
||
|
```
|