mixins\share.js
1234567891011121314151617181920212223242526272829303132333435
export default { data () { return { // 分享内容配置 share: { title: '默认标题', }, // 是否打开分享功能 share_show: true, } }, created () { // 创建的时候判断要不要隐藏 this.handleShareHide(); }, watch: { share_show () { // 被修改时判断要不要隐藏 this.handleShareHide(); }, }, methods: { // 隐藏分享功能 handleShareHide () { if(!this.share_show) { return uni.hideShareMenu(); } }, }, onShareAppMessage () { return { title: this.share.title, }; },}
main.js
12345678910111213141516
import Vue from 'vue'import App from './App'// 引入import share from 'mixins/share.js'Vue.config.productionTip = falseApp.mpType = 'app'// 全局注册Vue.mixin(share)const app = new Vue({ ...App})app.$mount()
使用
pages\index\index.vue
12345678910111213141516171819
<template> <view class="container">分享测试</view></template><script> export default { data () { return { share: { title: '新标题', // 标题覆盖 }, share_show: false, // 关闭分享 } }, onShow () { this.share_show = true; }, }</script>
hongfs.ʕ◔ϖ◔ʔ
文章
184
分类
13