VEUI

VEUI on GitHub
Play!中文

Alert

Examples

Statuses

Alert has four statuses: success, info, warning, and error. You can specify different statuses using the status prop.

Messages can either be specified in the default slot, or via the message prop.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-alert
    class="alert"
    status="success"
  >
    Your profile has been updated.
  </veui-alert>
  <veui-alert
    class="alert"
    status="info"
  >
    Press any key to continue...
  </veui-alert>
  <veui-alert
    class="alert"
    status="warning"
  >
    <code>slot-scope</code> is deprecated. Use <code>v-slot</code> instead.
  </veui-alert>
  <veui-alert
    class="alert"
    status="error"
    message="Uncaught SyntaxError: Unexpected token +"
  />
</article>
</template>

<script>
import { Alert } from 'veui'

export default {
  components: {
    'veui-alert': Alert
  }
}
</script>

<style lang="less" scoped>
.alert {
  margin-bottom: 20px;
}
</style>

Multiple messages

You can specify the message prop as an array to display multiple switchable messages.

Set the closable prop to true to allow the alert message to be closed by users. You can also use the close-label prop to make the close button shown as specified text.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-alert
    type="info"
    close-label="Got it"
    closable
    :open.sync="open"
    :message="messages"
  />
  <section v-if="!open">
    <veui-button @click="open = true">
      Open
    </veui-button>
  </section>
</article>
</template>

<script>
import { Alert, Button } from 'veui'

export default {
  components: {
    'veui-alert': Alert,
    'veui-button': Button
  },
  data () {
    return {
      open: true,
      messages: [
        'Component data must be a function.',
        'Prop definitions should be as detailed as possible.',
        'Always use key with v-for.',
        'Never use v-if on the same element as v-for.'
      ]
    }
  }
}
</script>

With title

Set the title prop to specify the message title.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-alert
    class="alert"
    status="success"
    title="消息标题"
  >
    Your profile has been updated.
  </veui-alert>
  <veui-alert
    class="alert"
    status="success"
  >
    Your profile has been updated.
    <template #title>
      消息标题
    </template>
  </veui-alert>
</article>
</template>

<script>
import { Alert } from 'veui'

export default {
  components: {
    'veui-alert': Alert
  }
}
</script>

<style lang="less" scoped>
.alert {
  margin-bottom: 20px;
}
</style>

Extra content

Use the extra slot to specify additional content after the message.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-alert
    class="alert"
    status="success"
    ui="strong"
    message="恭喜你,你的请求已成功处理"
    closable
  >
    <template #title>
      恭喜你
    </template>
    <template #extra>
      <veui-button ui="text">
        查看详情
      </veui-button>
    </template>
    恭喜你,你的请求已成功处理
  </veui-alert>
</article>
</template>

<script>
import { Alert, Button } from 'veui'

export default {
  components: {
    'veui-alert': Alert,
    'veui-button': Button
  }
}
</script>

<style lang="less" scoped>
.alert {
  margin-bottom: 20px;
}
</style>

API

Props

NameTypeDefaultDescription
statusstring'success'

The contextual status of the alert message.

ValueDescription
infoInformational status.
successSuccess status.
warningWarning status.
errorError status.
typestring'success'Deprecated. Use status instead.
titlestring-Message title.
messagestring | Array<string>-Message content. When an array is passed, multiple messages will be displayed and switchable.
closablebooleanfalseWhether to allow closing.
openbooleantrue

.sync

Whether the message is displayed.

indexnumber0

.sync

The index of the currently displayed message when there are multiple messages.

Slots

NameDescription
default

Message content area.

Default content: message text.

NameTypeDescription
messagestringThe message text.
indexnumberThe index value of the current message when there are multiple messages.
closefunctionUsed to close the alert.
titleThe content area of the message title.
extraThe additional content area after the message.
contentThe entire message area, including status icons, switch buttons, close buttons, etc.

Icons

NameDescription
successSuccess message.
warningWarning message.
infoInformational message.
errorError message.
prevPrevious message.
nextNext message.
closeClose the alert.
Edit this page on GitHubEdit
© Baidu, Inc. 2024