quasarframework / quasar-cli

[DEPRECATED, <= 0.17) Quasar Framework - CLI
https://quasar.dev
MIT License
202 stars 50 forks source link

Access to axios in prefetch({}) #231

Closed folamy closed 5 years ago

folamy commented 5 years ago

[v1] I think it would be better if axios and any other registered plugins in boot can access in prefetch like this preFetch ({ axios, store,......ssrContext }) { axios.get('/test')...... }

rstoenescu commented 5 years ago

What you are looking for is described at https://v1.quasar-framework.org/quasar-cli/cli-documentation/boot-files#Accessing-data-from-boot-files

folamy commented 5 years ago

I know about boot files..... but, since there is no access to ‘this.$axios..get() in prefetch()’ , what I’m looking for something like (nuxtjs asyncdata(context ){}), in which you can do context.axios.get(....) context.$storyblok.get(...)

rstoenescu commented 5 years ago

@folamy You're looking at this the wrong way. There's an example in docs with Axios that you can take a look at: https://v1.quasar-framework.org/quasar-cli/cli-documentation/boot-files#Axios

streof commented 5 years ago

If you're using the preFetch option, you have access to the store which is sufficient in order to dispatch some actions such as initial data load.

However, if you're using axios, you have to make sure that it receives the full path e.g. http://example.com/v1/get/initalData instead of just /v1/get/initialData. Otherwise you'll get a connect ECONNREFUSED 127.0.0.1:80 error (see SO)

Alternatively, you can use the proxy setting of axios in order to avoid using the full path.