我写了一个对image的封装,希望能够在image加载完毕后再进行渲染,但是这里有个问题就是我img的资源是通过wx,downloadfile下载后缓存的临时文件.我进行了如下调用,onload方法会被触发,this.parent输出的object的数据也是对的,但是对this.parent的任何属性修改,都不能实际影响this.parent,我打印restest对象的ready始终是fals


export  default class restest

{

    

constructor(resName) {

this.refCount = 0;

this.ready = false;

//check if exist in local file,if not download it

this.resName = resName;

this.Image = new Image;

}


    ActualLoad()

    {

        this.Image.src = this.resName;

        this.Image.parent = this

        this.Image.onload = function()

        {

            console.log("image width" )

            console.log(this.parent)

            this.parent.ready = true

        }

    }

}


展开全部
收起
2回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
  • 何加男

    20人对此回答表示赞同

    问题找出来了,如果出现加载的图片不存在的话,onload也会被调用的,但是似乎这时的调用传入的参数和对象很奇怪

    展开
    20
    0回复
    发布于 6年前

    评论(0)

    收起评论

  • Dominic

    14人对此回答表示赞同

    这是代码逻辑问题,建议给个代码片段,这样大家可以更容易帮助到你

    展开
    14
    0回复
    发布于 6年前

    评论(0)

    收起评论

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部