在Vue4.0开发微信公众号的时候,需要做微信分享功能。这个功能其实还算简单,具体的思路如下:
1.安装微信JSSDK和Axios(axios是http请求插件)
2.向后台请求微信配置参数
3.初始化微信分享配置API
4.需要分享的地方引用配置
那么现在来实现:
安装插件:
yarn add weixin-js-sdk
yarn add axios
安装好插件之后,创建一个weixinApi.js文件,添加如下代码:
import wx from 'weixin-js-sdk';
import Axios from"axios";
const ShareImpl= function(option) {//option是分享的配置内容*/
const url = window.location.href.split("#")[0];
window.console.log(url, JSON.stringify(option));
Axios.get('获取参数配置路径', {
params: {url}
}).then((response)=>{
wx.config({
debug:false,
appId: response.data.AppId,
timestamp: response.data.Timestamp,
nonceStr: response.data.NonceStr,
signature: response.data.S