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>
相关推荐
00后程序员张13 小时前
对比 Ipa Guard 与 Swift Shield 在 iOS 应用安全处理中的使用差异
android·开发语言·ios·小程序·uni-app·iphone·swift
郑州光合科技余经理17 小时前
技术架构:海外版外卖平台搭建全攻略
java·大数据·人工智能·后端·小程序·架构·php
00后程序员张17 小时前
在 iOS 设备上同时监控 CPU、GPU 与内存的方法
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者821 小时前
在 Windows、Linux 与 CI 环境下命令行上传 IPA 到 App Store
linux·windows·ios·ci/cd·小程序·uni-app·iphone
sheji341621 小时前
【开题答辩全过程】以 基于微信小程序的摄影器材租赁系统设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
毕设源码-邱学长21 小时前
【开题答辩全过程】以 基于微信小程序的社团管理系统的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
码农客栈1 天前
小程序学习(十五)之通用轮播组件
小程序
浔川python社1 天前
《C++ 小程序编写系列》(第七部):C++11 + 新特性实战 —— 性能与稳定性双提升
java·c++·小程序
码农客栈1 天前
小程序学习(十三)之请求和上传文件拦截器
小程序·uni-app
夏天想1 天前
解决小程序缓存时间是永久性得除非用户主动删除得问题
java·缓存·小程序