easy-web-share
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

WebShare - 网页分享 SDK

Npm Bundlephobia

网页端经常遇到的场景:点击右上角转发给好友或直接调起原生 APP 的分享。为了让分享后等到比较好的展示效果,比如标题、简略图片、描述等,开发者部的不对每个平台进行配置。由于但平台众多,每个平台都不一致,让人十分头疼。

支持平台

  • Web Social
  • QQ
  • QQ 空间
  • 微信

Usage

import webShare from 'easy-web-share'

webShare.setGlobalShareInfo({
  url: '分享地址',
  title: '分享标题',
  desc: '分享描述',
  imageUrl: '分享图片地址
})

// 更新分享信息
// SPA 应用需要在每个页面调用,否则会使用 GlobalShareInfo 的配置
webShare.setShareInfo({
  url: '分享地址',
  title: '分享标题',
  desc: '分享描述',
  imageUrl: '分享图片地址
})

手动创建

import { createWebShare } from 'easy-web-share'
const webShare = createWebShare({
  url: '分享地址',
  title: '分享标题',
  desc: '分享描述',
  imageUrl: '分享图片地址
})

特殊配置

在需要 SDK 才能设置分享内容的环境中,如微信、QQ ,如果没有加载对应的 jssdk,本项目会自动加载对应的 jssdk。

微信

在微信内分享必须借助微信 jssdk,且获取相应的接口权限,因此需要在页面加载时调用 wx.config 初始化 SDK.

wx.config({
  debugger: false,
  appId: 'your appId',
  timestamp,
  nonceStr: noncestr,
  signature,
  jsApiList: ['updateAppMessageShareData'],
})

API

setGlobalShareInfo

getGlobalShareInfo

setShareInfo

getShareInfo

Package Sidebar

Install

npm i easy-web-share

Weekly Downloads

332

Version

1.0.1

License

MIT

Unpacked Size

11.3 kB

Total Files

7

Last publish

Collaborators

  • lbb00