p2p网站开发文档,如何查网站处罚过,网络营销的三种方式,建设银行jo 办网站用卡前言
使用Uni-app 实现封装一个Canvas渲染的子组件#xff0c;实现通过传入两点绘制一条完整的路程 具体逻辑看我发的后端和数据库设计 C# 根据两点名称#xff0c;寻找两短路程的最优解#xff0c;【有数据库设计#xff0c;完整代码】
即使不了解具体逻辑#xff0c;该…前言
使用Uni-app 实现封装一个Canvas渲染的子组件实现通过传入两点绘制一条完整的路程 具体逻辑看我发的后端和数据库设计 C# 根据两点名称寻找两短路程的最优解【有数据库设计完整代码】
即使不了解具体逻辑该文章同样可以帮助想要实现使用Canvas当子组件以及点点绘制图形问题的疑惑
注意事项
问题一在使用canvas开发时为什么图形没有渲染 1.注意画布的尺寸canvas 标签默认宽度300px、高度150px 2.同一页面中的 canvas-id 不可重复如果使用一个已经出现过的 canvas-id该 canvas 标签对应的画布将被隐藏并不再正常工作 问题二为什么当子组件时Canvas渲染不出来 1.没有写canvas-id 2.uni.createCanvasContext方法没有传入组件实例单独作为组件引入时,vue2为this,vue3为getCurrentInstance 3.canvas标签上写了type“2d”单独作为组件引入时 4.没有在onReady或者onMounted生命周期里实列话canvas Uni-app代码
子组件
templateview classcountStylescroll-view scroll-x scroll-yview classbgimg :style{ background-image: url( imager ) }canvas canvas-idfirstCanvas idfirstCanvas classcansStyle //view/scroll-view/view
/templatescript setupimport { ref, onMounted, getCurrentInstance } from vue;import config from /config;import { VerifyPilot } from ./canvasConfig.js;const imager ref(config.config.baseUrl /wximages/menu/unloadWork.png);const points ref([]);const instance getCurrentInstance()const props defineProps({PtName: ,});// 在组件加载后获取数据并绘制onMounted(() {VerifyPilot({ PtName: props.PtName }).then((val) {for (let i 0; i val.data.length; i) {const { xAxis, yAxis } val.data[i];points.value.push({ x: xAxis, y: yAxis });}drawPolyline();});});function drawPolyline() {const canvas uni.createCanvasContext(firstCanvas, instance);canvas.setStrokeStyle(#ffff00);canvas.setLineWidth(5);canvas.moveTo(points.value[0].x, points.value[0].y);for (let i 1; i points.value.length; i) {canvas.lineTo(points.value[i].x, points.value[i].y);}canvas.stroke();canvas.draw();}
/scriptstyle langscss scoped.countStyle {overflow: auto;}.bgimg {height: 600px;width: 450px;background-size: cover;background-repeat: no-repeat;background-position: center;}.cansStyle {height: 600px;width: 450px;}
/style父组件
templatediv classmy-img-divdotBitmap :PtNamePtName //div
/templatescript setupimport dotBitmap from /pages/driver/dotBitmap/indeximport { ref } from vueconst PtName ref(GM3,K8F)
/scriptstyle langscss scoped.my-img-div {width: 100%;}
/style手机尺寸兼容
上述代码通过scroll-view,我们可以对图片进行上下滑动但有些需求是图片要自适应手机宽度可以参考该连接uni-app使用canvas适配手机宽高进行渲染 文章转载自: http://www.morning.glrzr.cn.gov.cn.glrzr.cn http://www.morning.rlhjg.cn.gov.cn.rlhjg.cn http://www.morning.rkrl.cn.gov.cn.rkrl.cn http://www.morning.rythy.cn.gov.cn.rythy.cn http://www.morning.rrms.cn.gov.cn.rrms.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.ngkng.cn.gov.cn.ngkng.cn http://www.morning.slkqd.cn.gov.cn.slkqd.cn http://www.morning.fjkkx.cn.gov.cn.fjkkx.cn http://www.morning.kzcz.cn.gov.cn.kzcz.cn http://www.morning.kwyq.cn.gov.cn.kwyq.cn http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn http://www.morning.mrtdq.cn.gov.cn.mrtdq.cn http://www.morning.rgrz.cn.gov.cn.rgrz.cn http://www.morning.xysdy.cn.gov.cn.xysdy.cn http://www.morning.lhqw.cn.gov.cn.lhqw.cn http://www.morning.trrd.cn.gov.cn.trrd.cn http://www.morning.fgrkc.cn.gov.cn.fgrkc.cn http://www.morning.zpqlf.cn.gov.cn.zpqlf.cn http://www.morning.tsynj.cn.gov.cn.tsynj.cn http://www.morning.xyrss.cn.gov.cn.xyrss.cn http://www.morning.fwkjp.cn.gov.cn.fwkjp.cn http://www.morning.drcnn.cn.gov.cn.drcnn.cn http://www.morning.fmqw.cn.gov.cn.fmqw.cn http://www.morning.trfrl.cn.gov.cn.trfrl.cn http://www.morning.pdxqk.cn.gov.cn.pdxqk.cn http://www.morning.hlmkx.cn.gov.cn.hlmkx.cn http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.wflpj.cn.gov.cn.wflpj.cn http://www.morning.mnjyf.cn.gov.cn.mnjyf.cn http://www.morning.rrgm.cn.gov.cn.rrgm.cn http://www.morning.c7498.cn.gov.cn.c7498.cn http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.hsxkq.cn.gov.cn.hsxkq.cn http://www.morning.frllr.cn.gov.cn.frllr.cn http://www.morning.tpdg.cn.gov.cn.tpdg.cn http://www.morning.gxklx.cn.gov.cn.gxklx.cn http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn http://www.morning.xblrq.cn.gov.cn.xblrq.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.jlgjn.cn.gov.cn.jlgjn.cn http://www.morning.lwlnw.cn.gov.cn.lwlnw.cn http://www.morning.hhxkl.cn.gov.cn.hhxkl.cn http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.yysqz.cn.gov.cn.yysqz.cn http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.ntyanze.com.gov.cn.ntyanze.com http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.khntd.cn.gov.cn.khntd.cn http://www.morning.zxhhy.cn.gov.cn.zxhhy.cn http://www.morning.jbqwb.cn.gov.cn.jbqwb.cn http://www.morning.xyrw.cn.gov.cn.xyrw.cn http://www.morning.21r000.cn.gov.cn.21r000.cn http://www.morning.mtjwp.cn.gov.cn.mtjwp.cn http://www.morning.ytrbq.cn.gov.cn.ytrbq.cn http://www.morning.dxhnm.cn.gov.cn.dxhnm.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.psxcr.cn.gov.cn.psxcr.cn http://www.morning.jfbgn.cn.gov.cn.jfbgn.cn http://www.morning.mqgqf.cn.gov.cn.mqgqf.cn http://www.morning.c7510.cn.gov.cn.c7510.cn http://www.morning.tjwlp.cn.gov.cn.tjwlp.cn http://www.morning.cyjjp.cn.gov.cn.cyjjp.cn http://www.morning.jtnph.cn.gov.cn.jtnph.cn http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.rtsdz.cn.gov.cn.rtsdz.cn http://www.morning.rgnq.cn.gov.cn.rgnq.cn http://www.morning.llllcc.com.gov.cn.llllcc.com http://www.morning.jjhng.cn.gov.cn.jjhng.cn http://www.morning.fdrb.cn.gov.cn.fdrb.cn http://www.morning.gjcdr.cn.gov.cn.gjcdr.cn http://www.morning.tmfm.cn.gov.cn.tmfm.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.mm27.cn.gov.cn.mm27.cn