小程序分享

单页面分享

复制代码
onShareAppMessage(res) {
			// 若为按钮触发分享,可通过res.target判断;此处默认分享整个列表页面
			return {
				title: `${this.caseList.length}个理疗案例分享`, // 分享标题
				path: `/pagesA/CustomerDetails/CustomerDetails?id=${this.ids}`, // 分享路径(需替换为你的页面实际路径)
				imageUrl: this.caseList.length > 0 ? `域名${this.caseList[0].tongue_img[0]}` : '/static/images/default-share.png', // 分享封面图(优先取第一个案例的舌象图,无则用默认图)
				desc: `包含${this.caseList.length}个理疗案例,涵盖多种理疗方案和舌象数据` // 分享描述
			}
		},
		// 微信小程序分享到朋友圈配置(仅支持小程序)
		onShareTimeline() {
			return {
				title: `${this.caseList.length}个理疗案例分享`,
				imageUrl: this.caseList.length > 0 ? `域名${this.caseList[0].tongue_img[0]}` : '/static/images/default-share.png',
				query: `id=${this.ids}` // 分享参数
			}
		},

全局分享

在项目根目录下新建 common 文件夹(若已存在可直接使用),在该文件夹内创建 globalShare.js 文件,用于编写全局分享的核心逻辑。

复制代码
// common/globalShare.js
export default {
  // 小程序分享给好友(必填)
  onShareAppMessage() {
    return {
      title: '全局默认分享标题', // 分享标题
      path: '/pages/index/index', // 分享跳转路径(必须是已在 pages.json 中注册的页面)
      imageUrl: '/static/share-default.png' // 分享封面图(可选,支持本地静态资源或网络图片)
    }
  },
  // 小程序分享到朋友圈(可选,仅微信小程序支持)
  onShareTimeline() {
    return {
      title: '全局默认朋友圈分享标题',
      imageUrl: '/static/share-default.png'
    }
  }
}

步骤 2:在 main.js 中全局注册混入

复制代码
// main.js
import Vue from 'vue'
import App from './App'
// 引入全局分享混入
import globalShare from './common/globalShare'

// 全局注册分享混入
Vue.mixin(globalShare)

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
  ...App
})
app.$mount()
相关推荐
m0_5261194013 天前
iconfont我修改好颜色,但是在小程序项目是黑色的
小程序
2601_9567436813 天前
2026 上海小程序开发甄选:源码、云函数、跨端兼容技术评判
小程序·开发经验·上海
IT_张三13 天前
CSDN-项目分享-暑期备考小程序
小程序
IsJunJianXin13 天前
pdd小程序 cdp 保存响应体
linux·服务器·小程序·pdd小程序·拼多多响应体解密·小程序cdp·拼多多rpc取响应体
Geek_Vison13 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas
weikecms13 天前
聚合返利CPS小程序快速搭建教程
人工智能·微信·小程序
Haibakeji14 天前
长沙餐饮门店点餐配送小程序定制开发
大数据·小程序
2501_9159184114 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
程序鉴定师14 天前
2026济南十大App制作公司测评(精简版):覆盖小程序、定制开发与跨平台方案
大数据·小程序
斯内普吖14 天前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源