Skip to content

support: update message content with key or reactive #45

@Syntax-J

Description

@Syntax-J
<template>
  <a-button type="primary" @click="openMessage">Open the message box (update by key)</a-button>
  <br />
  <br />
  <a-button type="primary" @click="openMessage2">
    Open the message box (update by reactive)
  </a-button>
</template>
<script lang="ts">
import { message } from 'ant-design-vue';
import { defineComponent, ref } from 'vue';
const key = 'updatable';
export default defineComponent({
  setup() {
    const openMessage = () => {
      message.loading({ content: 'Loading...', key });
      setTimeout(() => {
        message.success({ content: 'Loaded!', key, duration: 2 });
      }, 1000);
    };
    const content = ref('Loading...');
    const openMessage2 = () => {
      // content must use function
      message.loading({ content: () => content.value });
      setTimeout(() => {
        content.value = 'Loaded!';
      }, 1000);
    };
    return {
      openMessage,
      openMessage2,
    };
  },
});
</script>

ref: https://codesandbox.io/s/gmc46q?file=/src/demo.vue:745-752 (ant-design-vue: message)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions