vue微信H5项目中遇到的问题

目录

 

1.跳转页面,页面数据刷新路由不变化

2.微信支付路由层级问题

4.微信缓存导致调整内容不生效

5.vue install报错npm ERR!code ERESOLVE


1.微信H5跳转页面,页面数据刷新路由不变化


这种情况使用$route无法获取到当前页面路由传递的参数
解决方案:通过window.location.href获取当前的url进行拼接跳转
            this.$router.replace({path: "/pinPage?"+this.GetQueryString('type')});

Methods:{
            GetQueryString(name){
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
                var r = window.location.href.split('?')[window.location.href.split('?').length-1].match(reg); 
                if (r != null) return unescape(r[2]); 
                return null; 
            },
}

2.微信支付路由层级问题


通过this.$router.replace({ name: "topin17Day",params:{id:that.$route.query.id} })跳转路由,使路由层级超过一层将无法调起支付
解决方案:改为query拼接,或使用?拼接
this.$router.replace({path: "/pinPage?"+this.GetQueryString('type')});
that.$router.replace({ path: '/pinPage',query:{id:gid,type:1} });

3.微信二次分享,url自动拼接?from=message,导致出现两个问号,参数获取失败
解决方案:通过获取最后一个问号后面的参数
            this.GetQueryString('type');

Methods:{
            GetQueryString(name){
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
                var r = window.location.href.split('?')[window.location.href.split('?').length-1].match(reg); 
                if (r != null) return unescape(r[2]); 
                return null; 
            },
}

4.微信缓存导致调整内容不生效


解决方案:Last-Modified是页面的最后生成时间,GMT格式;设置永远是最新的
这个问题首先要搞清楚微信的缓存机制。据我观察,开发中频繁更新html文件,并不会缓存。猜测和服务器返回的Last-Modified有关。并且抓包发现,缓存时,微信没有向服务器请求html文件,改变服务器过期时间并没有用。
touch -m -t 11151101 abcd.html
修改文件的修改时间到一个比较旧的时间点,访问网页立即触发了缓存。
这就比较简单了,Last-Modified永远是最新的不就解决了。
立即动手,改变一下nginx设置,比如我们用Vue框架,入口页/mall/index.html.
location = /mall/index.html {
add_header Last-Modified $date_gmt;
}

5.vue install报错npm ERR!code ERESOLVE

解决方案:npm降低版本

npm install npm@6.14.6 -g

sudo npm install n -g

sudo n 12.18.3

vue报错解决:The .native modifier for v-on is only valid on components but it was used on <input>

事件的native修饰符只能在组件上使用,原生的html标签是不能使用的,这是因为我在input标签使用了native修饰符。

6.vue报错解决:npm ERR! vuemobilem@1.0.0 build: `node build/build.js`

目录

1.微信H5跳转页面,页面数据刷新路由不变化

2.微信支付路由层级问题

4.微信缓存导致调整内容不生效

5.vue install报错npm ERR!code ERESOLVE

vue报错解决:The .native modifier for v-on is only valid on components but it was used on <input>


删除node_modules重新构建

 

以下是Vue微信H5分享的代码示例: ```javascript export default { data() { return { shareTitle: '分享标题', shareDesc: '分享描述', shareLink: window.location.href, shareImgUrl: '分享图标url' } }, mounted() { this.initWechatShare() }, methods: { initWechatShare() { // 引入微信JS-SDK const wx = require('weixin-js-sdk') const url = window.location.href.split('#')[0] const data = { url } // 向后端请求签名数据 axios.get('/api/wechat/signature', { params: data }).then(res => { if (res.data.code === 0) { const signatureData = res.data.data wx.config({ debug: false, appId: signatureData.appId, timestamp: signatureData.timestamp, nonceStr: signatureData.nonceStr, signature: signatureData.signature, jsApiList: [ 'updateAppMessageShareData', 'updateTimelineShareData' ] }) wx.ready(() => { // 分享到朋友圈 wx.updateTimelineShareData({ title: this.shareTitle, // 分享标题 link: this.shareLink, // 分享链接 imgUrl: this.shareImgUrl, // 分享图标 success() { // 分享成功回调 } }) // 分享给朋友 wx.updateAppMessageShareData({ title: this.shareTitle, // 分享标题 desc: this.shareDesc, // 分享描述 link: this.shareLink, // 分享链接 imgUrl: this.shareImgUrl, // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 success() { // 分享成功回调 } }) }) } }) } } } ``` 在以上代码,我们使用 axios 向后端请求签名数据,获取 appId、timestamp、nonceStr 和 signature 等信息,然后使用微信 JS-SDK 进行配置和分享。分享到朋友圈使用的接口是 `wx.updateTimelineShareData`,分享给朋友使用的接口是 `wx.updateAppMessageShareData`。 注意,以上代码仅供参考,实际使用需要根据自己的情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值