Recently, when uniApp was used to develop wechat mini program, there was a demand for sharing and forwarding. There’s too much code to write onShareAppMessage for every page,vueMixins is a solution I feel good about, setting up a global share without going into the code:

Step 1: Write the share.js file

Path to the SRC/mixins/share. Js
export default {
  data() { 
    return {
      // Set the default share parameters
      share: {
        title: 'Here's the name of the applet.'./ / path
        path: '/pages/home/home'.imageUrl: ' '.desc: 'Here's a little program about XXXXXXXXXXXXXXXXX'.content: ' '}}},onShareAppMessage(res) {
    return {
      title: this.share.title,
      path: this.share.path,
      imageUrl: this.share.imageUrl,
      desc: this.share.desc,
      content: this.share.content,
      success(res) {
        uni.showToast({
          title: 'Share the success'})},fail(res) {
        uni.showToast({
          title: 'Share failure'.icon: 'none'})}}}}Copy the code

Step 2: Import in the main.js file

Import Vue from 'Vue' import App from './App' // import share from './mixins/share.js' vue.config.productionTip = False // Inject ue. Mixin (share) const app = new Vue({... App }) app.$mount()Copy the code

OVER (yeah it’s that easy, it’s OVER!!)