Quasar: How to get statics files using axios?

Created on 27 Oct 2019  路  2Comments  路  Source: quasarframework/quasar

I didn't find anything in docs...

For example:

const { data } = axios.get("/statics/markdown-examples/example.md");

Thanks!

bug

Most helpful comment

This question belongs to Axios plugin not to Quasar Framework. IMO, Quasar framework is not forcing you to use axios. I don't think its a bug.

All 2 comments

This question belongs to Axios plugin not to Quasar Framework. IMO, Quasar framework is not forcing you to use axios. I don't think its a bug.

Hi,

There are two scenarios:

  1. If your file is part of your /src folder (like in your example, /src/statics) then you're looking at this with the wrong mindset. You can use the webpack raw-loader (you need to install it) to dynamically load the file:
import(`!raw-loader!src/statics/markdown-examples/example.md`)
  .then(content => {
    // raw file content
    console.log(content.default)
  })

If you also want to get that md file compiled, you can directly use a webpack loader for markdown (add it a rule for md files that uses the loader in the Webpack config through quasar.conf.js > build > chainWebpack/extendWebpack()) -- which also has the benefit of doing this at build time rather than at runtime (and runtime assumes you need to load the md parser on the client bundle too).

  1. However, if you need to load the md file from a remote location, then indeed you'll need to use axios or other services to fetch the file, in which case it's best to get in touch with the developers of that service.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nueko picture nueko  路  3Comments

tombarfoot picture tombarfoot  路  3Comments

adwidianjaya picture adwidianjaya  路  3Comments

jean-moldovan picture jean-moldovan  路  3Comments

jippy89 picture jippy89  路  3Comments