這篇文章將為大家詳細講解有關(guān)怎么在vue項目中使用微信分享插件,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
吉林網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站開發(fā)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)自2013年創(chuàng)立以來到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
1.安裝weixin-js-sdk
npm install weixin-js-sdk
2.創(chuàng)建文件并引入
在src下創(chuàng)建common目錄
在common目錄下創(chuàng)建wxshare.js
3.在wxshare.js中編寫插件
import wx from 'weixin-js-sdk' import URL from '@/common/urlConfig' export const shareTitle = '測試'; export const shareUrl = '測試連接'; export const shareImg = '測試圖片'; export const shareDesc = '測試詳情'; /** *分享 * @param _this * @param shareTitle 標(biāo)題 * @param shareUrl 鏈接 * @param shareImg 圖片 * @param shareDesc 描述 */ export const commonShare = (_this, shareTitle, shareUrl, shareImg, shareDesc) => { let url = window.location.href; let data = { url: url }; _this.$axios.post(URL.vip.insertApplyRecord, data).then(res => { if (res.status == 1){ let data = res.data wx.config({ debug: false, // 開啟調(diào)試模式,調(diào)用的所有api的返回值會在客戶端alert出來,若要查看傳入的參數(shù),可以在pc端打開,參數(shù)信息會通過log打出,僅在pc端時才會打印。 appId: data.appId, // 必填,公眾號的唯一標(biāo)識 timestamp: data.timestamp, // 必填,生成簽名的時間戳 nonceStr: data.nonceStr, // 必填,生成簽名的隨機串 signature: data.signature, // 必填,簽名,見附錄1 jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage"] // 必填,需要使用的JS接口列表,所有JS接口列表見附錄2 }); wx.ready(function () { wx.onMenuShareTimeline({ title: shareTitle, // 分享標(biāo)題 link: shareUrl, // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致 imgUrl: shareImg, // 分享圖標(biāo) success: function () { // 用戶確認分享后執(zhí)行的回調(diào)函數(shù) // alert('分享成功?。?!'); }, cancel: function () { // 用戶取消分享后執(zhí)行的回調(diào)函數(shù) // alert('取消分享?。?!'); } }); wx.onMenuShareAppMessage({ title: shareTitle, // 分享標(biāo)題 desc: shareDesc, // 分享描述 link: shareUrl, // 分享鏈接,該鏈接域名或路徑必須與當(dāng)前頁面對應(yīng)的公眾號JS安全域名一致 imgUrl: shareImg, // 分享圖標(biāo) type: "", // 分享類型,music、video或link,不填默認為link dataUrl: "", // 如果type是music或video,則要提供數(shù)據(jù)鏈接,默認為空 success: function () { // 用戶確認分享后執(zhí)行的回調(diào)函數(shù) // alert('分享成功?。?!'); }, cancel: function () { // 用戶取消分享后執(zhí)行的回調(diào)函數(shù) // alert('取消分享?。?!'); } }); }); } }) };
4.在需要分享頁面編寫
import {commonShare, shareTitle, shareUrl, shareImg, shareDesc} from "@/common/wxshare"; commonShare(this, shareTitle, shareUrl, shareImg, shareDesc);
關(guān)于怎么在vue項目中使用微信分享插件就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
分享名稱:怎么在vue項目中使用微信分享插件
文章路徑:http://www.rwnh.cn/article26/psggcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、靜態(tài)網(wǎng)站、移動網(wǎng)站建設(shè)、定制網(wǎng)站、App開發(fā)、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)