naive-ui/demo/documentation/components/confirm/enUS/basic.md

63 lines
1.3 KiB
Markdown
Raw Normal View History

# Basic
2020-01-30 18:48:38 +08:00
Use `$NConfirm` to create a confirm modal.
```html
<n-button @click="handleConfirm">
Confirm
</n-button>
<n-button @click="handleSuccess">
Success
</n-button>
<n-button @click="handleError">
Error
</n-button>
```
```css
.n-button {
margin: 0 12px 8px 0;
}
```
```js
export default {
methods: {
handleConfirm (e) {
2020-01-30 18:48:38 +08:00
const confirmInstance = this.$NConfirm.warning({
title: 'Confirm',
2020-02-04 13:23:36 +08:00
content: 'Are you sure?',
positiveText: 'Sure',
negativeText: 'Not Sure',
onPositiveClick: (hide) => {
2020-02-04 13:23:36 +08:00
this.$NMessage.success('Sure')
hide()
},
onNegativeClick: (hide) => {
2020-02-04 13:23:36 +08:00
this.$NMessage.error('Not Sure')
hide()
}
2020-01-30 18:48:38 +08:00
})
},
handleSuccess (e) {
2019-12-13 18:19:46 +08:00
const confirmInstance = this.$NConfirm.success({
2020-01-30 18:48:38 +08:00
title: 'Success',
content:
2020-02-04 13:23:36 +08:00
'Cool',
positiveText: 'Wow!',
onPositiveClick: (hide) => {
2020-02-04 13:23:36 +08:00
this.$NMessage.success('Great!')
hide()
}
2020-01-30 18:48:38 +08:00
})
},
handleError(e) {
2019-12-13 18:19:46 +08:00
const confirmInstance = this.$NConfirm.error({
2020-01-30 18:48:38 +08:00
title: 'Error',
2020-02-04 13:23:36 +08:00
content: 'A mistake.',
positiveText: 'Ahhh!',
onPositiveClick: (hide) => {
2020-02-04 13:23:36 +08:00
this.$NMessage.success('I knew it...')
hide()
}
2020-01-30 18:48:38 +08:00
})
}
}
2020-01-30 18:48:38 +08:00
}
```