uniapp 小程序canvas插入网络图片

复制代码
<template>
  <view>
    <canvas canvas-id="myCanvas" style="width: 300px; height: 300px;"></canvas>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imagePath: ''
    };
  },
  methods: {
    getImageInfo() {
      uni.getImageInfo({
        src: 'https://aiapi.vip/1.jpg',
        success: (res) => {
          this.imagePath = res.path;
          this.drawCanvas();
        },
        fail: (err) => {
          console.log(err);
        }
      });
    },
    drawCanvas() {
      const ctx = uni.createCanvasContext('myCanvas', this);
      ctx.drawImage(this.imagePath, 0, 0, 300, 300);
      ctx.draw();
    }
  },
  mounted() {
    this.getImageInfo();
  }
}
</script>




<style>
	.container {
		display: flex;
		flex-wrap: wrap;
	}
</style>
相关推荐
2501_915921436 小时前
iOS App 电耗管理 通过系统电池记录、Xcode Instruments 与克魔(KeyMob)组合使用
android·ios·小程序·https·uni-app·iphone·webview
数字游民95278 小时前
2小时VibeCoding了一个看图猜词小程序:猜对了么
人工智能·ai·小程序·ai绘画·数字游民9527
qq_124987075313 小时前
基于小程序中医食谱推荐系统的设计(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·小程序·毕业设计·计算机毕业设计
2501_9159184117 小时前
iOS App 测试方法,Xcode、TestFlight与克魔(KeyMob)等工具组合使用
android·macos·ios·小程序·uni-app·iphone·xcode
棒棒的唐17 小时前
微信小程序右上角分享按钮如何根据用户登录状态确定是否允许分享
微信小程序·小程序
2501_9159214318 小时前
iOS 描述文件制作过程,从 Bundle ID、证书、设备到描述文件生成后的验证
android·ios·小程序·https·uni-app·iphone·webview
小白学大数据18 小时前
基于 Python 的知网文献批量采集与可视化分析
开发语言·爬虫·python·小程序
毕设源码-郭学长18 小时前
【开题答辩全过程】以 基于微信小程序的医院管理系统为例,包含答辩的问题和答案
微信小程序·小程序
毕设源码-朱学姐18 小时前
【开题答辩全过程】以 基于微信小程序的医疗物资进销存管理为例,包含答辩的问题和答案
微信小程序·小程序
低代码布道师19 小时前
教培管家第06讲:搭建销售工作台——公海争夺与私海管理
低代码·小程序·云开发