前提
在做畢設的時候,發現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無法顯示的問題。