mrTimofey / vue-ssr-starter

Starter kit for projects with Webpack 4, Vue 2 and SSR
53 stars 15 forks source link

server-side and client-side http request demo #1

Closed liamwang closed 7 years ago

liamwang commented 7 years ago

Can you add some demos of server-side and client-side http requests.

It is greatly appreciated.

mrTimofey commented 7 years ago

You can see some usage examples on the testable branch. There is only one request example from the vuex store but you can just use similar code within prefetch function if you want to fetch data into a component`s data. Something like that:

import http from 'src/http';

export default {
    data: () => ({ whatever: null })
    prefetch: () => http.get('whatever').then(res => ({
        whatever: res.data
    }))
}

Prefetching is just using Promises so you can do whatever you want and just resolve your promise object with any data you need.

liamwang commented 7 years ago

@mrTimofey Thank you for replying.