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>
相关推荐
爱怪笑的小杰杰1 天前
uni-app Vue3 国际化最佳实践:告别应用重启,优雅实现多语言切换
前端·vue.js·uni-app
yqcoder1 天前
uni-app 数据缓存详解
缓存·uni-app
2501_915921431 天前
穿越HTTPS迷雾:Wireshark中的TLS抓包秘诀与文件合并方法
网络协议·ios·小程序·https·uni-app·wireshark·iphone
PinTrust SSL证书1 天前
Sectigo(Comodo)企业型OV通配符SSL
网络·网络协议·网络安全·小程序·https·ssl
头发还在的女程序员1 天前
家政系统源码,上门家政源码,支持小程序、APP、H5和公众号,可直接搭建使用
小程序·生活·家政
小徐_23331 天前
uni-app 组件库 Wot UI 2.0 发布了,我们带来了这些改变!
前端·微信小程序·uni-app
黄华SJ520it1 天前
天美仕商城平台开发代码
小程序·软件需求·系统开发
yqcoder1 天前
uni-app 之 页面路由
uni-app
小离a_a1 天前
uniapp小程序添加路由全局限制,增加路由白名单,登录后接口跳转参数正常传递
小程序·uni-app
Giggle12181 天前
家政维修保洁预约上门服务小程序软件开发解析
大数据·小程序·产品运营·个人开发·内容运营