简体   繁体   English

Fabric JS:SVG无法从URL导入

[英]Fabric js: SVG cannot import from url

I am working with fabric js , & i am getting problem in importing SVG from url on local system 我正在使用Fabric js,并且在从本地系统上的URL导入SVG时遇到问题

fabric.loadSVGFromURL('svg/1.svg', function(objects, options) {
  var obj = fabric.util.groupSVGElements(objects, options);
  canvas.add(obj).renderAll();
});

& try also 并尝试

var site_url =  'svg/1.svg';
fabric.loadSVGFromURL(site_url, function(objects) { 
          var group = new fabric.PathGroup(objects, { 
          left: 165, 
          top: 100, 
          width: 295, 
          height: 211 
        }); 
        canvas.add(group); 
        canvas.renderAll(); 
          });

& getting error in console for both codes 在两个代码的控制台中出现错误

在此处输入图片说明

can anyone help to resolve this how to import svg from local system 任何人都可以帮助解决此问题如何从本地系统导入svg
Thanks in advane 感谢先进

 Takes url corresponding to an SVG document, and parses it into a set of fabric objects. Note that SVG is fetched via XMLHttpRequest, so it needs to conform to SOP (Same Origin Policy)



loadSVGFromURL: function(url, callback, reviver) {

    //put your  code here 

      url = url.replace(/^\n\s*/, '').trim();
      svgCache.has(url, function (hasUrl) {
        if (hasUrl) {
          svgCache.get(url, function (value) {
            var enlivedRecord = _enlivenCachedObject(value);
            callback(enlivedRecord.objects, enlivedRecord.options);
          });
        }
        else {
          new fabric.util.request(url, {
            method: 'get',
            onComplete: onComplete
          });
        }
      });

The problem is not with your code. 问题不在于您的代码。 I guess your opening the html file directly in your browser. 我想您是直接在浏览器中打开html文件。 This uses the file// protocol and doesn't support ajax requests. 这使用文件//协议,不支持ajax请求。 You should use a http server for your local system, and load your html through the http protocol. 您应该为本地系统使用http服务器,并通过http协议加载html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM