0

Currently my Nuxt.js application serves HTML pages defined in layouts, pages, routes and components.

Is it possible to render one single route / one page as a standard JSON Response? Is that possible? I mean do not render the HTML e.g. Tags - only pure JSON!

What I already tried:

  • Created a completely clean layout (with basically only in it), no succcess, still HTML.
  • Used <pre>{{jsonObject}}</pre> hoping to get plain JSON, no success.

Would be VERY happy, if somebody could tell me whether this is possible AT ALL or not?

1
  • not possible, you should use either a static file or make an API Commented Nov 2, 2021 at 9:54

1 Answer 1

2

What you're looking for here, is an API.

Vue.js will render a template (compiled to render functions, generating a DOM tree) at the end, because it's aimed towards a frontend usage. If you want to render something like an API response with pure JSON, you need to look into Express or alike.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, I do understand that. Of course, I could host an API/endpoints somehow else, yes. The motivation of my question was: Is it possible to integrate Express into my current Nuxt application anyways? Somehow at routing level inside Nuxt? So Nuxt serves all the frontend routes and serves/pipes the request for just ONE single route (which access Express in the background)? I do not want to setup a second project just for that one route AND I do need to process some logic (so I do not want to serve one single static file).
Nuxt can have a middleware baked into Express as metioned here: github.com/nuxt/nuxt.js/discussions/… Here is the related documentation: nuxtjs.org/docs/configuration-glossary/… @NetWurst

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.