https://developers.weixin.qq.com/community/develop/doc/000ea83ba5cb58a586feb827c59c00
跟这个问题一样
解决办法就是在onshow中奖地址清了重新赋值,就是缓存的问题
<div><web-view :src="pdfurl" :webview-styles="webviewStyles" ><cover-view class="share-button"><cover-view class="share-txt" ><cover-image @click="goPages(`/subPages/Industry/report/download?src=${pdfurl}&title=${title}`)" class="share-img" src="https://static.solarbe.com/zhangshang/xiazai.png"></cover-image></cover-view></cover-view></web-view>(生成分享图片)<canvas class="canvas" canvas-id="imgCanvas" style="width: 100%;height: 100%;position: absolute; top: -1000px; left: -1000px;"></canvas></div>
<script>import {reportLog} from '@/api/report/index.js'import util from '@/common/js/util.js';import {reportLists} from '@/api/report/index.js'export default{data(){return{title:'',desc:'',reportId:0,pdfurl:'',powerw: 0,shareUrl:'',webviewStyles: {progress: {color: '#FF3333'}}}},//分享到聊天onShareAppMessage() {console.log(this.shareUrl,'this.shareUrl')return {title: this.title,path: '/subPages/Industry/webView?title='+this.title+'&desc='+this.desc,imageUrl: this.shareUrl};},onShow() {let params = {page:uni.getStorageSync('productObj').page}//这里一定要清除一下,不然浏览器会觉得地址一样,不做任何操作this.pdfurl='';//这里要重新赋值,因为他在onshow的时候没有拿到reportLists(params).then((res)=>{res.data.forEach((item)=>{if(item.id==this.reportId||uni.getStorageSync('productObj').id){this.pdfurl = item.url;}})})},onLoad(options) {let {title,desc,id,url} = optionsthis.title = titlethis.desc = descthis.reportId = id// this.pdfurl = decodeURIComponent(url)// 设置titleuni.setNavigationBarTitle({title})// 设置分享wx.showShareMenu({withShareTicket: true,menus: ['shareAppMessage']});// 浏览量this.reportLog()let message = uni.getSystemInfoSync(); //获取手机信息this.powerw = message.windowWidth / 375;const ctx = uni.createCanvasContext('imgCanvas');ctx.font = 'bold 15rpx serif'ctx.setTextAlign('left')ctx.setFillStyle("#000000")/**ctx: 画布的上下文环境content: 需要绘制的文本内容drawX: 绘制文本的x坐标drawY: 绘制文本的y坐标lineHeight:文本之间的行高lineMaxWidth:每行文本的最大宽度lineNum:最多绘制的行数*/this.textPrewrap(ctx, this.desc, 15 * this.powerw, 30 * this.powerw, 20 * this.powerw, 350, 8);var that = thisctx.draw(true, () => {setTimeout(function() {uni.canvasToTempFilePath({canvasId: 'imgCanvas',fileType: 'jpg',x: 0,y: 0,width: 500,height: 400,destWidth: 500,height: 400,success: function(res) {that.shareUrl = res.tempFilePathconsole.log(that.shareUrl,11111)// 在这里保存图片},fail: function(error) {console.log(error)}, })}, 100)})},methods:{reportLog(){let params = {'report_id':this.reportId}reportLog(params).then((res)=>{})},goPass(url){uni.redirectTo({url:url})},textPrewrap(ctx, content, drawX, drawY, lineHeight, lineMaxWidth, lineNum) {var drawTxt = ''; // 当前绘制的内容var drawLine = 1; // 第几行开始绘制var drawIndex = 0; // 当前绘制内容的索引content = content.replace(/\s*/g,"")// 判断内容是否可以一行绘制完毕if (ctx.measureText(content).width <= lineMaxWidth) {ctx.fillText(content.substring(drawIndex, i), drawX, drawY);} else {for (var i = 0; i < content.length; i++) {drawTxt += content[i];if (ctx.measureText(drawTxt).width >= lineMaxWidth) {if (drawLine >= lineNum) {ctx.fillText(content.substring(drawIndex, i) + '..', drawX, drawY);break;} else {ctx.fillText(content.substring(drawIndex, i + 1), drawX, drawY);drawIndex = i + 1;drawLine += 1;drawY += lineHeight;drawTxt = '';// if(uni.getSystemInfoSync().osName === "ios"){// }// console.log(drawY,'drawY',content)}} else {// 内容绘制完毕,但是剩下的内容宽度不到lineMaxWidthif (i === content.length - 1) {ctx.fillText(content.substring(drawIndex), drawX, drawY);}}}}},}}
</script>
<style scoped>image{width: 30rpx;}.dowload{height: 100rpx;}.share-button {z-index: 999999;position: fixed;color: red;display: flex;justify-content: end;align-items: center;bottom:300rpx;width:100%;height: 100rpx;right: 20rpx;}
</style>