This article mainly introduces the detailed WeChat sharing ideas about the global configuration of the Vue project. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it.
This project is a mobile project. Mainly used to access public account services. The project uses two login methods, WeChat authorized login and account and password login. For mobile projects, in order to facilitate project expansion and provide development hot update speed, the project is divided into different modules, each module is a single-page application. There are two types of pages, one that requires users to log in before they can browse, and the other that users can browse without logging in. No matter which one is used, WeChat sharing is configured.
Technology used
1. Use vue as the framework
2. Use vux as the UI component library
Global configuration of WeChat Sharing ideas
1. Distinguish between general and special. In general, the default sharing copy is configured globally; there are two special cases. One is that the shared content does not need to be obtained asynchronously, and is configured when the route jumps. , the other is that the shared content needs to be obtained asynchronously, and the shared content needs to be updated after the asynchronous content is obtained.
2. For content that does not need to be obtained asynchronously, we use the method defined in the routing meta-information and directly call the public function to update the shared content after each routing jump.
For details, please check the usage instructions of WeChat JSSDK
// wxShare.js import Vue from 'vue' // 在组件外使用vux集成的微信jssdk import { WechatPlugin, AjaxPlugin } from 'vux' Vue.use(WechatPlugin) Vue.use(AjaxPlugin) export default function wxShare ({title, desc, timelineTitle, link, imgUrl} = {}) { Vue.wechat.config({ debug: false, appId: appId, timestamp: timestamp, nonceStr: nonceStr, signature: signature, jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline'] }) Vue.wechat.ready(() => { Vue.wechat.onMenuShareAppMessage({ title: title, // 分享标题 desc: desc || '默认分享文案', // 分享描述 link: link || window.location.href, // 分享链接 imgUrl: imgUrl || '图标地址(必须是有效的Link)' // 分享图标 }) Vue.wechat.onMenuShareTimeline({ title: timelineTitle || desc || '默认分享文案', // 分享标题,由于分享到朋友圈没有desc,所以这里采用的策略是,指定的朋友圈分享标题优先,其次采用发送给朋友的描述,最后采用默认文案。 link: link || window.location.href, // 分享链接 imgUrl: imgUrl || '图标地址(必须是有效的Link)' // 分享图标 }) }) Vue.wechat.error((res) => { }) } // 为Vue的原型对象添加该方法,则所有vue实例都能继承该方法 Vue.prototype.$wxShare = wxShare // router/index.js 每个模块都有自己内部的路由配置 // codes... const routes = [ { path: '/index', name: 'index', redirect: '/index/homepage', children: [ { path: '/index/homepage', name: 'homepage', component: homepage meta: { title: '这是主页', shareDesc: '这是本站的主页', desc: 'homepage, click and see!', timelineTitle: '这是首页,欢迎点击关注,blablablablabla~~~', imgUrl: 'http://frankzhang.me/wp-content/uploads/2017/08/cropped-favicon-01.png' } }, ] } ] // routerRule,公共路由配置,所有模块共用一个路由控制策略 import wxShare from '@/utils/wxShare' export default function routerRule (router) { // other codes... router.afterEach(( to, from ) => { wxShare({ title: to.meta.title, desc: to.meta.shareDesc, link: to.meta.shareLink, logo: to.meta.shareLogo}) }) } // main.js import routerRule from ... routerRule(router)
After the above configuration, router.afterEach will call wxShare once, re-read the meta information in the router and redefine the WeChat sharing content to achieve The purpose of combining global configuration and special configuration.
Shared content that needs to be obtained asynchronously
In this case, we can use the created hook of the vue instance and call wxShare once in the successful callback of obtaining the data.
// homepage.vue <script> export default { data() { return { } }, created() { getHomepageInfo() .then( res => { this.$wxShare({ title: res.title, desc: res.desc, imgUrl: res.logo }) } ) } } </script>
Points to note
1. If the project adopts non-history mode, you need to remove the part after # on the URL and pass it to the backend in exchange for WeChat signature.
2. According to WeChat official instructions:
All pages that need to use JS-SDK must first inject configuration information, otherwise they will not be able to be called (the same url only needs to be called once, for changes in the url The SPA web app can be called every time the url changes...
Due to the SPA application, after the url changes, it needs to be reconfigured once and the configuration information of the current page is re-injected, so this step must be done in the router. Called in afterEach! Because according to the instructions of vue-router, the global afterEach hook is called after the navigation is confirmed. At this time, the navigation has been confirmed and the url has changed. The WeChat signature can be re-obtained for the updated url ##.
#Related recommendations:webpack vue project development environment LAN binding IP method
The above is the detailed content of Vue project global configuration WeChat sharing ideas. For more information, please follow other related articles on the PHP Chinese website!

夸克网盘和百度网盘都是很便利的存储工具,不少的用户们都在询问这两款软件互通吗?夸克网盘怎么分享到百度网盘?下面就让本站来为用户们来仔细的介绍一下夸克网盘的文件怎么保存到百度网盘方法吧。 夸克网盘的文件怎么保存到百度网盘方法 1、想要知道怎么把夸克网盘的文件转到百度网盘,首先在夸克网盘上下载需要保存的文件,然后打开百度网盘客户端后,选择压缩文件要保存的文件夹,双击打开该文件夹。 2、打开该文件夹后,点击窗口左上角区域的“上传”。 3、在电脑中找到需要上传的压缩文件,点击选

win7系统如何分享wifi热点?我们电脑在连接了网络之后,也是可以进行无线网络的分享的。很多用户想要将自己电脑的网络分享到手机上来使用。很多小伙伴不知道怎么详细操作,小编下面整理了win7系统如何分享wifi热点的操作方法步骤,如果你感兴趣的话,跟着小编一起往下看看吧! win7系统如何分享wifi热点的操作方法步骤 1、要想开启wifi热点,首先得要有无线网卡,笔记本是有自带的,pc的话可以购买一个随身wifi来分享wifi,这里就不叙述了。首先按下键盘上的windows键打开开始菜

芒果TV拥有各种类型的电影、电视剧、综艺等资源,用户可以在其中自由的选择进行观看。芒果tv会员不仅能够看到全部的VIP剧而且还能够设置最高清的画质,帮助用户爽快看剧,下面小编就给大家带来一些芒果tv免费的会员账号供用户们使用,赶紧来看一看吧。芒果tv最新会员账号免费分享2023:注意:都是收集的最新会员账号,可以直接登录使用,不要随意的修改密码。账号:13842025699密码:qds373账号:15804882888密码:evr6982账号:13330925667密码:jgqae账号:1703

win7企业版激活密钥有没有最新的?如果你安装的是官方win7企业版,会提示用windows7企业版产品密钥来激活,否则不能正常使用。所以小编接下来跟大家分享一些win7企业版激活密码,大家一起来看看吧。Q3VMJ-TMJ3M-99RF9-CVPJ3-Q7VF3KGMPT-GQ6XF-DM3VM-HW6PR-DX9G8MT39G-9HYXX-J3V3Q-RPXJB-RQ6D79JBBV-7Q7P7-CTDB7-KYBKG-X8HHCP72QK-2Y3B8-YDHDV-29DQB-QKWWM6JQ

惠普打印机是很多办公室内必备的打印设备,在电脑上安装打印机驱动,可以完美解决打印机无法连接等等问题。那么惠普打印机驱动怎么安装?下面小编就给大家介绍两个惠普打印机驱动程序安装方法。 第一种方法:官网下载驱动 1、在搜索引擎中搜索惠普中国官网,在支持一栏中,选择【软件与驱动程序】。 2、选择【打印机】分类,在搜索框中输入你的打印机型号,点击【提交】,即可查找到你的打印机驱动。 3、根据你电脑的系统选择对应的打印机,win10即选择win10系统的驱动。 4、下载成功后,在文件夹中找到

番茄小说是丰富的小说宝库,其中汇聚了海量优质的小说资源。在这里,你可以根据自己的喜好,从多种不同类型的小说中挑选出心仪之作。对于热爱阅读的你,这无疑是一片可以自由翱翔的文学天地。有的时候遇到心仪的读物也像分享给好友一起阅读,但是很多用户们还不清楚究竟该如何分享,那么这篇教程攻略就将为大家带来详细的攻略介绍,想要了解的玩家们就快来跟着本文一起阅读吧!番茄小说怎么分享书给好友?1、打开番茄小说,点击进入小说,点击右上角分享图标。2、选择分享渠道,这里小编以分享至微信好友为例。3、点击分享。4、即可查

wps是一款颇受欢迎的办公软件,无论是在学习、工作还是生活中,都能大大提高工作效率。我们经常会将wps文件分享给需要的朋友,具体要怎么操作呢?下面就由小编来演示一下详细操作。 1、打开需要分享的文件。 2、点击文件,再点击分享文档。 3、权限选择仅指定人可查看/编辑,然后点击创建并分享。 4、然后点击复制链接。 5、打开自己要分享的途径,如分享微信好友,在输入框点击鼠标右键,选择粘贴。 6、然后点击发送就可以了。

很多朋友在喵喵记账软件里会有自己的欲购清单,想要分享给其他好友时该怎么操作呢?下面为大家介绍一下分享时的操作方法。1.在手机中点击打开喵喵记账软件进入后,在页面的右下角点击“我的”进行切换。2.在个人中心页面里找到“购物清单”这一项后点击打开。3.接下来进入到我的购物清单界面里,在“欲购清单”选项卡的下方会看到自己设置的购物清单列表,在要分享的选项上面点击进入。4.在清单详情页的右上方点击并排的三个小圆点图标。5.这时图标下会弹出一个窗口,在里面点击选择“分享清单”这一项即可分享给其他好友。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
