packages/vant/src/action-bar/README.md
Used to provide convenient interaction for page-related operations.
Register component globally via app.use, refer to Component Registration for more registration ways.
import { createApp } from 'vue';
import { ActionBar, ActionBarIcon, ActionBarButton } from 'vant';
const app = createApp();
app.use(ActionBar);
app.use(ActionBarIcon);
app.use(ActionBarButton);
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="Icon1" @click="onClickIcon" />
<van-action-bar-icon icon="cart-o" text="Icon2" @click="onClickIcon" />
<van-action-bar-icon icon="shop-o" text="Icon3" @click="onClickIcon" />
<van-action-bar-button type="danger" text="Button" @click="onClickButton" />
</van-action-bar>
import { showToast } from 'vant';
export default {
setup() {
const onClickIcon = () => showToast('Click Icon');
const onClickButton = () => showToast('Click Button');
return {
onClickIcon,
onClickButton,
};
},
};
Use badge prop to show badge in icon.
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="Icon1" dot />
<van-action-bar-icon icon="cart-o" text="Icon2" badge="5" />
<van-action-bar-icon icon="shop-o" text="Icon3" badge="12" />
<van-action-bar-button type="warning" text="Button" />
<van-action-bar-button type="danger" text="Button" />
</van-action-bar>
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="Icon1" color="#ee0a24" />
<van-action-bar-icon icon="cart-o" text="Icon2" />
<van-action-bar-icon icon="star" text="Collected" color="#ff5000" />
<van-action-bar-button type="warning" text="Button" />
<van-action-bar-button type="danger" text="Button" />
</van-action-bar>
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="Icon1" />
<van-action-bar-icon icon="shop-o" text="Icon2" />
<van-action-bar-button color="#be99ff" type="warning" text="Button" />
<van-action-bar-button color="#7232dd" type="danger" text="Button" />
</van-action-bar>
| Attribute | Description | Type | Default |
|---|---|---|---|
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | boolean | true |
| placeholder | Whether to generate a placeholder element | boolean | false |
| Attribute | Description | Type | Default |
|---|---|---|---|
| text | Button text | string | - |
| icon | Icon | string | - |
| color | Icon color | string | #323233 |
| icon-class | Icon class name | string | Array | object | '' |
| icon-prefix | Icon className prefix | string | van-icon |
| dot | Whether to show red dot | boolean | - |
| badge | Content of the badge | number | string | - |
| badge-props | Props of Badge, see Badge - props | BadgeProps | - |
| url | Link URL | string | - |
| to | The target route should navigate to when clicked on, same as the to prop of Vue Router | string | object | - |
| replace | If true, the navigation will not leave a history record | boolean | false |
| disabled | Whether to disable icon | boolean | false |
| Attribute | Description | Type | Default |
|---|---|---|---|
| text | Button text | string | - |
| type | Button type, Can be set to default primary success warning danger | string | default |
| color | Button color, support linear-gradient | string | - |
| icon | Left Icon | string | - |
| disabled | Whether to disable button | boolean | false |
| loading | Whether to show loading status | boolean | false |
| url | Link | string | - |
| to | The target route should navigate to when clicked on, same as the to prop of Vue Router | string | object | - |
| replace | If true, the navigation will not leave a history record | boolean | false |
| Name | Description |
|---|---|
| default | Text |
| icon | Custom icon |
| Name | Description |
|---|---|
| default | Button content |
The component exports the following type definitions:
import type {
ActionBarProps,
ActionBarIconProps,
ActionBarButtonProps,
} from 'vant';
The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
| Name | Default Value | Description |
|---|---|---|
| --van-action-bar-background | var(--van-background-2) | - |
| --van-action-bar-height | 50px | - |
| --van-action-bar-icon-width | 48px | - |
| --van-action-bar-icon-height | 100% | - |
| --van-action-bar-icon-color | var(--van-text-color) | - |
| --van-action-bar-icon-size | 18px | - |
| --van-action-bar-icon-font-size | var(--van-font-size-xs) | - |
| --van-action-bar-icon-active-color | var(--van-active-color) | - |
| --van-action-bar-icon-text-color | var(--van-text-color) | - |
| --van-action-bar-icon-background | var(--van-background-2) | - |
| --van-action-bar-button-height | 40px | - |
| --van-action-bar-button-warning-color | var(--van-gradient-orange) | - |
| --van-action-bar-button-danger-color | var(--van-gradient-red) | - |