アラート

柔軟性のあるアラートメッセージで、典型的なユーザーアクションに対して文脈に沿ったフィードバックメッセージを提供します。

Examples

任意の長さのアラートを表示できます。オプションで閉じるボタンがあります。 適切なスタイルを設定するには、8つの required コンテキストクラスのいずれかを使用します(例: theme="success"

vue
<template>
 <Alert color="primary">
  A simple primary alert—check it out!
 </Alert>
 <Alert color="secondary">
  A simple secondary alert—check it out!
 </Alert>
 <Alert color="success">
  A simple success alert—check it out!
 </Alert>
 <Alert color="danger">
  A simple danger alert—check it out!
 </Alert>
 <Alert color="warning">
  A simple warning alert—check it out!
 </Alert>
 <Alert color="info">
  A simple info alert—check it out!
 </Alert>
 <Alert color="light">
  A simple light alert—check it out!
 </Alert>
 <Alert color="dark">
  A simple dark alert—check it out!
 </Alert>
</template>

Link color

AlertLink コンポーネントを適用すると、リンクが適切なカラーになります。

vue
<template>
 <Alert color="primary">
  A simple primary alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="secondary">
  A simple secondary alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="success">
  A simple success alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="danger">
  A simple danger alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="warning">
  A simple warning alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="info">
  A simple info alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="light">
  A simple light alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
 <Alert color="dark">
  A simple dark alert with
  <AlertLink>an example link</AlertLink>
  . Give it a click if you like.
 </Alert>
</template>

Additional content

アラートには、 見出し、段落、仕切りなどのHTML要素を含めることができます。

vue
<template>
 <Alert color="success">
  <AlertHeading>Well done!</AlertHeading>
  <p>
   Aww yeah, you successfully read this important alert message. This example
   text is going to run a bit longer so that you can see how spacing within
   an alert works with this kind of content.
  </p>
  <hr />
  <b-p margin="b-0">
   Whenever you need to, be sure to use margin utilities to keep things nice
   and tidy.
  </b-p>
 </Alert>
</template>

Icons

vue
<template>
 <Alert
  color="primary"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   flex="shrink-0"
   margin="e-2"
   aria-label="Warning:"
  />
  <div>An example alert with an icon</div>
 </Alert>
</template>

同じアイコンを繰り返し簡単に参照できるようにすることもできます。NuxtIcons を使用し SVGスプライトを作成してる例をご覧ください。

vue
<template>
 <Alert
  color="primary"
  flex
  align-items="center"
 >
  <BIcon
   v-bootstrap
   icon="bi:info-circle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Info:"
  />
  <div>An example alert with an icon</div>
 </Alert>
 <Alert
  color="success"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:check-circle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Success:"
  />
  <div>An example success alert with an icon</div>
 </Alert>
 <Alert
  color="warning"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Warning:"
  />
  <div>An example warning alert with an icon</div>
 </Alert>
 <Alert
  color="danger"
  flex
  align-items="center"
 >
  <BIcon
   icon="bi:exclamation-triangle-fill"
   color="currentColor"
   flex="shrink-0"
   margin="e-2"
   aria-label="Danger:"
  />
  <div>An example danger alert with an icon</div>
 </Alert>
</template>

Dismissing

CloseButton コンポーネント を使用すると、アラートインラインを消すことができます。

ライブデモを見ることができます:

vue
<template>
 <Alert
  color="warning"
  dismissible
  fade
 >
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
  <CloseButton dismiss="alert" />
 </Alert>
</template>

Triggers

解除は、以下に示すように、アラート内のボタンのdismiss属性で行うことができます。

vue
<template>
 <Alert
  color="warning"
  dismissible
  fade
 >
  <b-button
   color="primary"
   dismiss="alert"
  >
   Close
  </b-button>
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
  <CloseButton dismiss="alert" />
 </Alert>
</template>

または、以下のようにtargetを使用してアラートの外側のボタンに表示します。

vue
<template>
 <Alert
  id="my-alert"
  color="warning"
  dismissible
  fade
 >
  <strong>Holy guacamole!</strong>
  You should check in on some of those fields below.
 </Alert>
 <b-button
  color="primary"
  dismiss="alert"
  target="#my-alert"
 >
  Close
 </b-button>
</template>

Methods

MethodDescription
toggle 手動で切り替えます
show 手動で開きます
hide 手動で非表示にします