导入流星内的svg文件 [英] import svg files inside meteor

查看:118
本文介绍了导入流星内的svg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用流星+ react作为前端和后端的项目.

I'm working on a project using meteor + react as front-and-back end.

对于前端UI,我使用的是element-react(

For front-end UI, I am using element-react (https://eleme.github.io/element-react/#/en-US/quick-start) which is really cool and awesome. However when I tried to import element-react into my project (as instructed in the quick start of element-react homepage), meteor failed to compile static files and returned "Uncaught Error: Cannot find module './assets/error.svg''" which is the file do exist and has correct relative path.

是否缺少某些内容或流星,我们根本无法使用"require('./assets/error.svg')"来加载svg图像?

Is there something missing or in meteor we simply can not use "require('./assets/error.svg')" to load a svg image?

推荐答案

根据

According to this post in Meteor's forum.

您可以使用流星方法和Assets API之类的方法从服务器中获取大多数数据.像

You can use something like Meteor methods and the Assets API to get most any data from your server though. Something like

/server/main.js

Meteor.methods({
  'svg.get'(data) {
    return Assets.getText(data.path)
  }
})

/client/main.js

  const getSVG = async (path) => {
    return await new Promise((resolve, reject) => {
      Meteor.call('svg.get', { path }, (err, res) => {
        if (err) reject('Something went wrong')
        resolve(res)
      })
    })
  }

const SVG = await getSVG('some/path/relative/to/private/file.svg') 

这篇关于导入流星内的svg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆