A
A
andrei242018-04-02 19:07:29
JavaScript
andrei24, 2018-04-02 19:07:29

How is the request sent to the ssr application?

Hello.
How does sending a request to get data in vuejs (ssr) + node express server work?
I am building an ssr application, indexing is very important and that the data is received before the page is displayed. To work, I took the nuxtjs.org framework and the node express server.
Application structure:
api.site.ru - api without authorization
site.ru - application + express server
On the main site.ru, requests to api.site.ru immediately go:

<template>
...
</template>

<script>
    import axios from 'axios'

    export default {
        async asyncData({ params }) {
            console.log('server ajax')
            let { data } = await axios.get('http://api.site.ru/companies')

            return { companies: data }
        }
    }
</script>

I run npm run dev. When opening site.ru, no ajax goes. The node express request was sent by the server. Everything works great.
Then I create the second page site.ru/new (new.vue) the same code with an ajax request. And when switching between pages, the browser sends the usual ajax, but if you immediately drive in site.ru/new, then there is no request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2018-04-03
@andrei24

So everything is correct, if you load a tab, then this request will be executed on the server, and on the client it will already follow the links without reloading. In nuxt-link, the "a" tag is inside. asyncData is called on the server to receive data, and on the client when the SPA application is switched.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question