有沒有人在Vue中使用過此組件?無法訪問Vue中的自定義畫布屬性
https://www.npmjs.com/package/aframe-draw-component。
我想使用「aframe-draw-component」的高級用法。 它使用原始html,但不vue.js。 codepen example
// html
<a-scene fog="type: exponential; color:#000">
<a-sky acanvas rotation="-5 -10 0"></a-sky>
</a-scene>
// js
const chars = 'ABCDEFGHIJKLMNOPQRWXYZ'.split('')
const font_size = 8
AFRAME.registerComponent("acanvas", {
dependencies: ["draw"],
init: function(){
console.log(this.el.components)
this.draw = this.el.components.draw // get access to the draw component
this.draw.canvas.width = '512'
this.draw.canvas.height = '512'
this.cnvs = this.draw.canvas
const columns = this.cnvs.width/font_size
this.drops = []
for (let x = 0; x < columns; x++) {
this.drops[x] = 1
}
this.ctx = this.draw.ctx
},
tick: function() {
this.ctx.fillStyle = 'rgba(0,0,0,0.05)'
this.ctx.fillRect(0, 0, this.cnvs.width, this.cnvs.height)
this.ctx.fillStyle = '#0F0'
this.ctx.font = font_size + 'px helvetica'
for(let i = 0; i < this.drops.length; i++) {
const txt = chars[Math.floor(Math.random() * chars.length)]
this.ctx.fillText(txt, i * font_size, this.drops[i] * font_size)
if(this.drops[i] * font_size > this.cnvs.height && Math.random() > 0.975) {
this.drops[i] = 0 // back to the top!
}
this.drops[i] = this.drops[i] + 1
}
this.draw.render()
}
})
無論身在何處,我把Vue的成分,我得到這個錯誤:
App.vue B405:124未捕獲的(以諾)類型錯誤:在不確定的 無法讀取屬性「畫布」 NewComponent.init(EVAL在
它不能找到自定義依賴「畫」。
有人可以幫我嗎?
謝謝。
請提供一些您嘗試過的代碼,以便某人可能有機會以某種方式幫助您。 – Cobaltway