fabricjs 設置背景顏色與文字背景顏色等無法更新頁面內容

前提

在做畢設的時候,發現fabric.Textbox中有一些屬性設置之後,刷新頁面無法觸發

代碼演示

//  this.gettersTarget 是選取的fabric對象
// 這裏是watch檢測input值是否發生變化
 backgroundColor (newValue) {
      if (this.watcherFlag()) {
        let {color} = newValue
        this.gettersTarget.backgroundColor = color
        this.canvas.renderAll()
      }
    },

在這裏插入圖片描述
在這裏插入圖片描述
如圖,input值改變了,但是文字背景沒有發生變化

解決方案:set()

通過閱讀api,可以發現官方提供了一個觸發更新的方法。
在這裏插入圖片描述

    backgroundColor (newValue) {
      if (this.watcherFlag()) {
        let {color} = newValue
        // this.gettersTarget.backgroundColor = color
        this.gettersTarget.set('backgroundColor', color)
        jsPageToobar.updateOoption(this.gettersTarget, 1, 'backgroundColor', newValue)
        this.canvas.renderAll()
      }
    },

使用之後就可以解決設置fabric的對象值的時候,更新canvas無法顯示的問題。
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章