vuejs / vue-hackernews-2.0

HackerNews clone built with Vue 2.0, vue-router & vuex, with server-side rendering
MIT License
10.96k stars 2.15k forks source link

asyncData as Nuxt #382

Open baha96 opened 4 years ago

baha96 commented 4 years ago

how to implement as nuxt AsyncData, for example:

async asyncData({ route }) {
           try { 
                const { results }= await axios.get('/blog/', { page: route.query.page || '1' });
                return {
                    items: results,
                    query: {
                       page: route.query.page || '1'
                   }
               };
            } catch (e) {
                return {
                    items: [],
                    query: {
                        page: route.query.page || '1'
                    }
               }
            }
 },
watchQuery: true,

and then inside the template call items without use store

================== and how to use it here?

tomphilpotts commented 4 years ago

Hey,

I ran into this problem too, I've been working on a boilerplate ssr to test a few things out.

Take a look: https://github.com/BoldAnchor/Vue-SSR-Boilerplate

I am using: https://github.com/Akryum/vue-cli-plugin-ssr

It's a working progress...

baha96 commented 4 years ago

Hey,

I ran into this problem too, I've been working on a boilerplate ssr to test a few things out.

Take a look: https://github.com/BoldAnchor/Vue-SSR-Boilerplate

I am using: https://github.com/Akryum/vue-cli-plugin-ssr

It's a working progress...

the template generated an error

./src/entry-client.js 3:0-9 "export 'createApp' was not found in './main' ... ./src/entry-server.js 16:14-23 "export 'createApp' was not found in './main'

removing main.js from your codes, you removed the extra code....(I could not even check)

tomphilpotts commented 4 years ago

the template generated an error

./src/entry-client.js 3:0-9 "export 'createApp' was not found in './main' ... ./src/entry-server.js 16:14-23 "export 'createApp' was not found in './main'

removing main.js from your codes, you removed the extra code....(I could not even check)

I pushed an update around the same time you posted. Should be fine, I'm not getting an error.