uniapp 小程序分享功能


上個月在做小程序的項目時,甲方需要給小程序添加個分享的功能,查看uniapp官方文檔后,發現uniapp有自帶的小程序分享功能(https://uniapp.dcloud.io/api/plugins/share),里面一堆的參數介紹,你們自己看看吧。我這里就自己封裝了一個,哪個頁面需要就在哪個頁面調用

1、創建一個js文件(share.js)

export default{
    data(){
        return {
                       //設置默認的分享參數
            share:{
                title:'ALAPI',
                path:'/pages/index/index',
                imageUrl:'',
                desc:'',
                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:'分享成功'
                })
            },
            fail(res){
                uni.showToast({
                    title:'分享失敗',
                    icon:'none'
                })
            }
        }
    }
}

2、全局使用, 在 main.js 里面 添加全局的 mixin

import share from '@/....你的路徑.../share.js'

Vue.mixin(share)

 

3、在需要的頁面進行調用就行啦

export default {
data(){
        return {
                       //設置默認的分享參數
            share:{
                title:'ALAPI',
                path:'/pages/index/index',
                imageUrl:'',
                desc:'',
                content:''
            }
        }
    },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM