百度智能小程序 關(guān)注

2020-09-03 16:15 更新

follow 關(guān)注

解釋?zhuān)?關(guān)注組件,內(nèi)容/用戶關(guān)注組件。開(kāi)發(fā)者可在小程序內(nèi)配置關(guān)注組件,實(shí)現(xiàn)用戶對(duì)內(nèi)容和用戶的關(guān)注,可嵌套在原生組件內(nèi),自定義選擇組件的樣式和動(dòng)效。

屬性說(shuō)明

屬性名類(lèi)型必填默認(rèn)值說(shuō)明

mode

String

text

關(guān)注按鈕模式,有三種選擇。 icon :僅有圖標(biāo); text :文字版本; mixture :圖標(biāo)文字結(jié)合。

background-color

String

blue

mode 為 mixture 時(shí)不支持自定義背景色,默認(rèn)背景為藍(lán)色;當(dāng)且僅當(dāng) mode 為 text 時(shí)有以下 4 種按鈕顏色可選 blue 、 white 、 opacity 、 none 。當(dāng)且僅當(dāng) mode 為 icon 時(shí)有以下 2 種按鈕顏色可選 blue 、 white 。

is-followed

Boolean

false

關(guān)注的狀態(tài)

follow-text

Array

['關(guān)注', '已關(guān)注']

關(guān)注按鈕上的文案

is-show-toast

Boolean

true

關(guān)注后的結(jié)果反饋是否彈出 toast 提示

toast-text

Array

['關(guān)注成功', '已取消關(guān)注']

toast 文案,默認(rèn)為關(guān)注成功、已取消關(guān)注。

bind:follow

EventHandle

點(diǎn)擊按鈕事件

示例 

在開(kāi)發(fā)者工具中打開(kāi)


代碼示例

安裝組件:

<view>關(guān)注</view>
<view class="con-demo">
    <c-follow
        is-followed="{{isFollowed1}}"
        bind:follow="onFollow1">
    </c-follow>

    <c-follow
        background-color="white"
        follow-text="{{followText}}"
        is-followed="{{isFollowed2}}"
        bind:follow="onFollow2">
    </c-follow>

    <c-follow
        background-color="opacity"
        follow-text="{{followText2}}"
        is-followed="{{isFollowed4}}"
        bind:follow="onFollow4">
    </c-follow>

    <c-follow
        background-color="none"
        follow-text="{{followText}}"
        is-followed="{{isFollowed3}}"
        bind:follow="onFollow3">
    </c-follow>
</view>

<view class="con-demo">
    <c-follow
        mode="icon"
        background-color="white"
        is-followed="{{isFollowed5}}"
        bind:follow="onFollow5">
    </c-follow>

    <c-follow
        mode="icon"
        is-followed="{{isFollowed6}}"
        bind:follow="onFollow6">
    </c-follow>
</view>

<view class="con-demo">
    <c-follow
        mode="mixture"
        is-followed="{{isFollowed}}"
        bind:follow="onFollow">
    </c-follow>
</view>
Page({
    data: {
        isFollowed: true,
        followText: ['關(guān)注', '取消關(guān)注'],
        followText2: ['關(guān)注', '已經(jīng)取消關(guān)注']
    },
    onFollow() {
        let isFollowed = this.data.isFollowed;
        this.setData('isFollowed', !isFollowed);
    },
    onFollow1() {
        let isFollowed = this.data.isFollowed1;
        this.setData('isFollowed1', !isFollowed);
    },
    onFollow2() {
        let isFollowed = this.data.isFollowed2;
        this.setData('isFollowed2', !isFollowed);
    },
    onFollow3() {
        let isFollowed = this.data.isFollowed3;
        this.setData('isFollowed3', !isFollowed);
    },
    onFollow4() {
        let isFollowed = this.data.isFollowed4;
        this.setData('isFollowed4', !isFollowed);
    },
    onFollow5() {
        let isFollowed = this.data.isFollowed5;
        this.setData('isFollowed5', !isFollowed);
    },
    onFollow6() {
        let isFollowed = this.data.isFollowed6;
        this.setData('isFollowed6', !isFollowed);
    }
});
.con-demo {
    display: flex;
    height: 80px;
    align-items: center;
    justify-content: space-around;
    background: #666;
    height: 50px;
}
{
    "navigationBarTitleText": "標(biāo)題",
    "usingComponents": {
        "c-follow": "@smt-ui/content-component/src/follow"
    }
}


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)