我不认为这一定是基于Vue的问题,但我遇到了一些麻烦.
我想在画布上写一个Vue变量.如果删除vue,我的初始代码可以正常工作,但是如果添加vue,画布实际上不会启动.
这是我的密码
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = "black";
ctx.font="20px Georgia";
ctx.fillText("Hello World!",10,50);
var v = new Vue({
el: '#app',
data: {
'exampleContent': 'This is TEXT'
},
watch: {
exampleContent: function(val, oldVal) {
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.fillStyle = "black";
ctx.font="20px Georgia";
ctx.fillText(this.exampleContent,10,50);
}
}
});
如果我注释掉/* var v = new Vue({ ...
,那么最初的一位是有效的.如果我在watcher中记录exampleContent
的值,这也会起作用.但画布上有些东西不起作用.
要使用的演示: