百度智能小程序 頁(yè)面的事件處理函數(shù)

2020-09-05 14:45 更新

onShareAppMessage

解釋:頁(yè)面的事件處理函數(shù),用戶點(diǎn)擊右上角轉(zhuǎn)發(fā)。

Web 態(tài)說明:Web 態(tài)小程序暫不支持。

詳情參見頁(yè)面相關(guān)事件處理函數(shù)。    

示例 

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

代碼示例 1

<view class="wrap">
    <view class="card-area">
        <view class="tip-week">發(fā)送內(nèi)容(以下字段可自由適配)</view>
        <view class="list-area">
            <view class="list-item-key-4">標(biāo)題</view>
            <input class="list-item-value" bindinput="dataInput" data-type="title" value="{{shareData.title}}" type="text" placeholder="請(qǐng)輸入key" />
        </view>
        <view class="list-area">
            <view class="list-item-key-4">內(nèi)容</view>
            <input class="list-item-value" bindinput="dataInput" data-type="content" value="{{shareData.content}}" type="text" placeholder="請(qǐng)輸入key" />
        </view>
        <view class="list-area">
            <view class="list-item-key-4">跳轉(zhuǎn)頁(yè)面</view>
            <input class="list-item-value" bindinput="dataInput" data-type="path" value="{{shareData.path}}" type="text" placeholder="請(qǐng)輸入key" />
        </view>
        <button type="primary" open-type="share" hover-stop-propagation="true">點(diǎn)擊打開分享面板</button>
        <view class="tip-week">點(diǎn)擊右上角菜單或者點(diǎn)擊button轉(zhuǎn)發(fā)給好友</view>
    </view>
</view>
Page({
    data: {
        shareData: {
            title: '小程序標(biāo)題',
            content: '世界很復(fù)雜,百度更懂你',
            path: 'api/onShareAppMessage/onShareAppMessage'
        }
    },

    onShareAppMessage() {
        this.data.shareData.path += '?fr=shareApp';
        return this.data.shareData;
    },

    dataInput(e) {
        let type = e.currentTarget.dataset.type;
        let dataInput = e.detail.value;
        switch (type) {
            case 'title': {
                let title = 'shareData.title';
                this.setData({
                    [title]: dataInput
                });
                break;
            }
            case 'content': {
                let content = 'shareData.content';
                this.setData({
                    [content]: dataInput
                });
                break;
            }
            case 'path': {
                let path = 'shareData.path';
                this.setData({
                    [path]: dataInput
                });
                break;
            }
        }
    }
});


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

掃描二維碼

下載編程獅App

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

編程獅公眾號(hào)