codecamp

百度智能小程序 页面的事件处理函数

onShareAppMessage

解释:页面的事件处理函数,用户点击右上角转发。

Web 态说明:Web 态小程序暂不支持。

详情参见页面相关事件处理函数。    

示例 

在开发者工具中打开

代码示例 1

<view class="wrap">
    <view class="card-area">
        <view class="tip-week">发送内容(以下字段可自由适配)</view>
        <view class="list-area">
            <view class="list-item-key-4">标题</view>
            <input class="list-item-value" bindinput="dataInput" data-type="title" value="{{shareData.title}}" type="text" placeholder="请输入key" />
        </view>
        <view class="list-area">
            <view class="list-item-key-4">内容</view>
            <input class="list-item-value" bindinput="dataInput" data-type="content" value="{{shareData.content}}" type="text" placeholder="请输入key" />
        </view>
        <view class="list-area">
            <view class="list-item-key-4">跳转页面</view>
            <input class="list-item-value" bindinput="dataInput" data-type="path" value="{{shareData.path}}" type="text" placeholder="请输入key" />
        </view>
        <button type="primary" open-type="share" hover-stop-propagation="true">点击打开分享面板</button>
        <view class="tip-week">点击右上角菜单或者点击button转发给好友</view>
    </view>
</view>
Page({
    data: {
        shareData: {
            title: '小程序标题',
            content: '世界很复杂,百度更懂你',
            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;
            }
        }
    }
});


百度智能小程序 获取用户信息(已弃废)
百度智能小程序 调起分享面板
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

百度智能小程序开发文档

百度智能小程序 组件

百度智能小程序 地图

百度智能小程序 画布

百度智能小程序 API

百度智能小程序 界面

百度智能小程序 关注小程序引导组件

百度智能小程序 自定义组件

百度智能小程序 媒体

百度智能小程序 设备

百度智能小程序 拨打电话

百度智能小程序 内存警报

百度智能小程序 手机联系人

百度智能小程序 用户截屏事件

百度智能小程序 第三方平台

百度智能小程序 开放接口

百度智能小程序 百度收银支付

百度智能小程序 分包预下载

百度智能小程序 数据分析

百度智能小程序 服务端

百度智能小程序 云开发

百度智能小程序 初始化

百度智能小程序 云函数

百度智能小程序 服务端初始化

百度智能小程序 服务器获取上下文

百度智能小程序 服务端云函数

百度智能小程序 开发教程

百度智能小程序 功能开发

百度智能小程序 基本原理

百度智能小程序 小程序自动化

百度智能小程序 视频教程

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }