Vue.js Konva library to display a simple image, what am I missing?

让人想犯罪 __ 提交于 2019-11-29 11:59:54

The trick seems to be to make configImg reactive by putting it in a computed property, since the image will load after mounting.

export default {
  data() {
    return {
      testImg: new Image(100, 100),
      configKonva: {
        width: 200,
        height: 200
      }
    }
  },
  computed: {
    configImg: function() {
      return {
        x: 20,
        y: 20,
        image: this.testImg,
        width: 200,
        height: 200,
      }
    }
  },
  mounted() {
    this.testImg.src = "https://konvajs.github.io/assets/lion.png"
  }
}   
  mounted() {
    this.testImg.onload = () => this.$refs.layerImg.getStage().draw()
    this.testImg.src = "https://konvajs.github.io/assets/lion.png"
  }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!