除了支持 通用属性 以外,还支持如下属性。
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
value |
string |
- |
否 |
分享按钮组件的文本。 |
title |
string |
- |
否 |
分享标题。 |
description |
string |
- |
否 |
分享描述。 |
icon |
string |
- |
否 |
分享图片的url。 |
url |
string |
- |
否 |
分享到不支持运行快应用的设备(比如ios设备)时,跳转至此链接。 |
path |
string |
- |
否 |
分享路径,若为空则默认使用当前页面路径。 |
params |
object |
- |
否 |
自定义参数,允许开发者自由配置, 使用方式请参见setMenubarData中的shareParams参数。 |
platforms |
array |
- |
否 |
分享到的平台,不填则默认分享所有平台。 可用值包括:WEIBO(新浪微博)、QQ、WEIXIN(微信好友)、WEIXIN_CIRCLE(微信朋友圈)、SYSTEM(系统分享)。 |
usepageparams |
boolean |
false |
否 |
是否使用页面参数。 |
除了支持 通用样式 以外,还支持如下样式。
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
color |
color |
rgba(0, 0, 0, 0.87) |
否 |
文本颜色。 |
font-size |
length |
37.5px |
否 |
文本尺寸。 |
width |
length |
128px |
否 |
组件宽度。 |
height |
length |
70px |
否 |
组件高度。 |
除了支持通用事件以外,还支持如下事件。
名称 |
参数 |
描述 |
|---|---|---|
success |
{code: codeValue, content: contentValue} |
分享成功回调。
|
fail |
{code: codeValue, content: contentValue} |
分享失败回调。
|
cancel |
{code: codeValue, content: contentValue} |
分享取消回调。
|
<template>
<div class="container" designWidth="device-width">
<share-button
value="share button text"
title="title"
description="description"
icon="https://www-file.huawei.com/-/media/corporate/images/home/logo/huawei_logo.png"
url="https://www.huawei.com"
path="/Home/Page1"
params="{key1: value1, key2: value2}"
platforms="[WEIXIN, WEIXIN_CIRCLE, SYSTEM]"
usepageparams=false,
onsuccess="success()"
onfail="fail()"
oncancel="cancel()"
></share-button>
</div>
</template>
<style>
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
</style>
<script>
import prompt from '@system.prompt';
module.exports = {
data: {
componentData: {},
},
success(event){
console.log("sharesuccess "+ JSON.stringify(event));
prompt.showToast({
message: 'sharesuccess, details in console log',
})
},
fail(event){
console.log("sharefail "+ JSON.stringify(event));
prompt.showToast({
message: 'sharefail, details in console log',
})
},
cancel(event){
console.log("sharecancel "+ JSON.stringify(event));
prompt.showToast({
message: 'sharecancel, details in console log',
})
},
onInit() {
this.$page.setTitleBar({
text: 'menu',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5,
menu: true
});
},
}
</script>