用于為頁(yè)面相關(guān)操作提供便捷交互。
通過(guò)以下方式來(lái)全局注冊(cè)組件,更多注冊(cè)方式請(qǐng)參考組件注冊(cè)。
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="客服" @click="onClickIcon" />
<van-action-bar-icon icon="cart-o" text="購(gòu)物車(chē)" @click="onClickIcon" />
<van-action-bar-icon icon="shop-o" text="店鋪" @click="onClickIcon" />
<van-action-bar-button type="danger" text="立即購(gòu)買(mǎi)" @click="onClickButton" />
</van-action-bar>
import { Toast } from 'vant';
export default {
setup() {
const onClickIcon = () => Toast('點(diǎn)擊圖標(biāo)');
const onClickButton = () => Toast('點(diǎn)擊按鈕');
return {
onClickIcon,
onClickButton,
};
},
};
在 ActionBarIcon 組件上設(shè)置 dot 屬性后,會(huì)在圖標(biāo)右上角展示一個(gè)小紅點(diǎn);設(shè)置 badge 屬性后,會(huì)在圖標(biāo)右上角展示相應(yīng)的徽標(biāo)。
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="客服" dot />
<van-action-bar-icon icon="cart-o" text="購(gòu)物車(chē)" badge="5" />
<van-action-bar-icon icon="shop-o" text="店鋪" badge="12" />
<van-action-bar-button type="warning" text="加入購(gòu)物車(chē)" />
<van-action-bar-button type="danger" text="立即購(gòu)買(mǎi)" />
</van-action-bar>
通過(guò) ActionBarIcon 的 color 屬性可以自定義圖標(biāo)的顏色。
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" />
<van-action-bar-icon icon="cart-o" text="購(gòu)物車(chē)" />
<van-action-bar-icon icon="star" text="已收藏" color="#ff5000" />
<van-action-bar-button type="warning" text="加入購(gòu)物車(chē)" />
<van-action-bar-button type="danger" text="立即購(gòu)買(mǎi)" />
</van-action-bar>
通過(guò) ActionBarButton 的 color 屬性可以自定義按鈕的顏色,支持傳入 linear-gradient 漸變色。
<van-action-bar>
<van-action-bar-icon icon="chat-o" text="客服" />
<van-action-bar-icon icon="shop-o" text="店鋪" />
<van-action-bar-button color="#be99ff" type="warning" text="加入購(gòu)物車(chē)" />
<van-action-bar-button color="#7232dd" type="danger" text="立即購(gòu)買(mǎi)" />
</van-action-bar>
參數(shù) | 說(shuō)明 | 類(lèi)型 | 默認(rèn)值 |
---|---|---|---|
safe-area-inset-bottom | 是否開(kāi)啟底部安全區(qū)適配 | boolean | true
|
參數(shù) | 說(shuō)明 | 類(lèi)型 | 默認(rèn)值 |
---|---|---|---|
text | 按鈕文字 | string | - |
icon | 圖標(biāo) | string | - |
color | 圖標(biāo)顏色 | string | #323233
|
icon-class | 圖標(biāo)額外類(lèi)名 | string | Array | object | - |
icon-prefix v3.0.17
|
圖標(biāo)類(lèi)名前綴,等同于 Icon 組件的 class-prefix 屬性 | string | van-icon
|
dot | 是否顯示圖標(biāo)右上角小紅點(diǎn) | boolean | false
|
badge | 圖標(biāo)右上角徽標(biāo)的內(nèi)容 | number | string | - |
url | 點(diǎn)擊后跳轉(zhuǎn)的鏈接地址 | string | - |
to | 點(diǎn)擊后跳轉(zhuǎn)的目標(biāo)路由對(duì)象,等同于 vue-router 的 to 屬性 | string | object | - |
replace | 是否在跳轉(zhuǎn)時(shí)替換當(dāng)前頁(yè)面歷史 | boolean | false
|
參數(shù) | 說(shuō)明 | 類(lèi)型 | 默認(rèn)值 |
---|---|---|---|
text | 按鈕文字 | string | - |
type | 按鈕類(lèi)型,可選值為 primary info warning danger
|
string | default
|
color | 按鈕顏色,支持傳入 linear-gradient 漸變色 |
string | - |
icon | 左側(cè)圖標(biāo)名稱(chēng)或圖片鏈接 | string | - |
disabled | 是否禁用按鈕 | boolean | false
|
loading | 是否顯示為加載狀態(tài) | boolean | false
|
url | 點(diǎn)擊后跳轉(zhuǎn)的鏈接地址 | string | - |
to | 點(diǎn)擊后跳轉(zhuǎn)的目標(biāo)路由對(duì)象,等同于 vue-router 的 to 屬性 | string | object | - |
replace | 是否在跳轉(zhuǎn)時(shí)替換當(dāng)前頁(yè)面歷史 | boolean | false
|
名稱(chēng) | 說(shuō)明 |
---|---|
default | 文本內(nèi)容 |
icon | 自定義圖標(biāo) |
名稱(chēng) | 說(shuō)明 |
---|---|
default | 按鈕顯示內(nèi)容 |
組件提供了下列 CSS 變量,可用于自定義樣式,使用方法請(qǐng)參考 ConfigProvider 組件。
名稱(chēng) | 默認(rèn)值 | 描述 |
---|---|---|
--van-action-bar-background-color | var(--van-white) | - |
--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-gray-7) | - |
--van-action-bar-icon-background-color | var(--van-white) | - |
--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) | - |
更多建議: