I am trying to use fabricjs with vue.js but facing some problems. Here's my code -
var app = new Vue({
el: '#content_vue',
data: {
},
methods: {
add_image: function() {
var vm = this;
fabric.loadSVGFromURL('/images/sample.svg', function(objects, options) {
for (var i = 0; i < objects.length; i++) {
if (objects[i].get('type') == 'text') { //text일때
var iText = textChangeToIText(fabric.cssRules[options.svgUid], objects[i], options);
objects[i] = iText;
}
objects[i].setCoords();
vm.canvas.add(objects[i]);
}
vm.canvas.renderAll();
}, reviver);
}
},
created: function() {
var canvas = new fabric.Canvas('my_canvas', {
backgroundColor: "white"
});
this.canvas = canvas;
canvas.selection = false; // disable group selection
var iText4 = new fabric.IText('abcdefg\nhijklmnop', {
left: 200,
top: 50,
fontFamily: 'Lobster',
caching: false
});
canvas.add(iText4);
canvas.renderAll();
}
});
function reviver(element, object) {
if (object.get('type') == 'text') {
var childrens = [].slice.call(element.childNodes);
object.temp = childrens;
var tmpArr = element.getAttribute('y');
//var arr = tmpArr[tmpArr.length-1].split(')');
//console.log(element);
//console.log(object.top);
//object.top = parseFloat(arr[0]);
}
object.id = element.getAttribute('id');
};
This should now initialize fabricjs but when I use in vue.js, it is still not working. How can I fix it?