naive-ui/demo/documentation/components/message/zhCN/manuallyClose.md
2020-02-04 13:40:10 +08:00

612 B

手动关闭

<n-button @click="openMessage">
  打开
</n-button>
<n-button @click="closeMessage">
  关闭
</n-button>
export default {
  data() {
    return {
      message: null
    }
  },
  beforeDestroy () {
    this.closeMessage()
  },
  methods: {
    openMessage () {
      if (!this.message) {
        this.message = this.$NMessage.info('3 * 3 * 4 * 4 * ?', {
          duration: 0
        })
      }
    },
    closeMessage () {
      if (this.message) {
        this.message.hide()
        this.message = null
      }
    }
  }
}
.n-button {
  margin: 0 12px 8px 0
}