naive-ui/demo/documentation/components/confirm/enUS/basic.md
2020-03-16 16:54:16 +08:00

1.2 KiB

Basic

Use $NConfirm to create a confirm modal.

<n-button @click="handleConfirm">
  Confirm
</n-button>
<n-button @click="handleSuccess">
  Success
</n-button>
<n-button @click="handleError">
  Error
</n-button>
.n-button {
  margin: 0 12px 8px 0;
}
export default {
  methods: {
    handleConfirm (e) {
      const confirmInstance = this.$NConfirm.warning({
        title: 'Confirm',
        content: 'Are you sure?',
        positiveText: 'Sure',
        negativeText: 'Not Sure',
        onPositiveClick: () => {
          this.$NMessage.success('Sure')
        },
        onNegativeClick: () => {
          this.$NMessage.error('Not Sure')
        }
      })
    },
    handleSuccess (e) {
      const confirmInstance = this.$NConfirm.success({
        title: 'Success',
        content:
          'Cool',
        positiveText: 'Wow!',
        onPositiveClick: () => {
          this.$NMessage.success('Great!')
        }
      })
    },
    handleError(e) {
      const confirmInstance = this.$NConfirm.error({
        title: 'Error',
        content: 'A mistake.',
        positiveText: 'Ahhh!',
        onPositiveClick: () => {
          this.$NMessage.success('I knew it...')
        }
      })
    }
  }
}