Skip to content

how to use asyncData ? #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mesutgok opened this issue Jan 22, 2019 · 8 comments
Closed

how to use asyncData ? #51

mesutgok opened this issue Jan 22, 2019 · 8 comments

Comments

@mesutgok
Copy link

mesutgok commented Jan 22, 2019

Hi,

how to use asyncData ? I have problem app init vuex state data.

Good works

 App running at:
  - Local:   http://localhost:8001
(node:10829) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'errorMessage' of undefined
    at app.js:3606:20
(node:10829) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not
 handled with .catch(). (rejection id: 716)
@p1n5u
Copy link
Contributor

p1n5u commented Feb 8, 2019

Can you provide a demo repo or a sandbox with your code in it? With a simple log message, it is difficult to point out the issue.

Thanks

@hmillison
Copy link
Contributor

Does this library support an asyncData method in Vuex or Vue? I don't see any references to it in the code or the docs?

@p1n5u
Copy link
Contributor

p1n5u commented Feb 8, 2019

The asyncData hook is only needed for vue <=2.5 and is not natively supported. You can refer to the vue ssr guide so see how to implement it.
If you use vue 2.6 or greater you can use the serverPrefetch hook which is natively supported for prefetching data on the server side. https://ssr.vuejs.org/guide/data.html#logic-collocation-with-components

@hmillison
Copy link
Contributor

thanks @p1n5u. I had been trying to use serverPrefetch, but it wasn't working due to an issue from another library.

@p1n5u
Copy link
Contributor

p1n5u commented Feb 8, 2019

@hmillison could you make a repo with your code? I would like to take a closer look at the issue you have 🙂

@hmillison
Copy link
Contributor

hmillison commented Feb 12, 2019

Im using this with vue-class-component, which has not added “serverPrefetch” to their list of component hooks: vuejs/vue-class-component#312

@mesutgok
Copy link
Author

@p1n5u @hmillison vue cli ssr plugin and axios data fetch ssr using repo share pls ? I have problem api call vuex inital state not update

@Igor-Golovtsov
Copy link

Igor-Golovtsov commented Feb 19, 2020

@mesutgok hi, try use serverPrefetch for data fetch

serverPrefetch() {
  return this.fetchUsers();
},
methods: {
  fetchUsers() {
    return this.$store.dispatch('getUsers');
  },
}

@mesutgok mesutgok closed this as completed Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants