question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue implementation with async data

See original GitHub issue

Hello, first off, thanks for the great plugin!

So I’ve been trying to build a Vue.js demo that used this prerender-spa-plugin to generate a static site. I’ve got a good start but was wondering if you could shed some light on some questions I have.

First off, the repo is here --> https://github.com/stursby/vue-prerender-spa-demo

And live Demo --> https://vue-prerender-spa-demo.surge.sh/

So to the issues/questions/etc:

  • The ajax data is correctly being rendered in the HTML, but my ajax request is sill being made
  • So, is there a way to either to inject that JSON data as a window object during build? (or maybe add a ssr="true" key somewhere so I could check in my Vue app an not make the ajax request
  • I’ve currently got the captureAfterTime set to 1000ms… but I know this is fragile. I’ve tried some of the other methods with no success… any help here would be great

Any thoughts would be much appreciated! Thanks 🙌

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20

github_iconTop GitHub Comments

1reaction
stursbycommented, Aug 16, 2017

I just have it locally. Looks like this:

Config:

     // Prerender
      console.log(` 🚀 Prerendering...`)
      const prerenderPlugin = new PrerenderSpaPlugin(
        // entry
        path.join(__dirname, '/dist'),
        // routes
        ['/', '/about', ...usersRoutes],
        // options
        { captureAfterDocumentEvent: 'render-done' }
      )
      config.plugins.push(prerenderPlugin)

Vue: component

<script>
async mounted() {
    const url = 'https://jsonplaceholder.typicode.com/users'
    const { data } = await axios.get(url)
    this.users = data
    this.$nextTick(() => {
      document.dispatchEvent(new Event('render-done'))
    })
  }
</script>

Is the issue that I’m only dispatching the Event in Vue components that fetch data?

I see that you can combine captureAfterTime and captureAfterDocumentEvent but not sure how to implement that… do I define both keys?

0reactions
drewlustrocommented, Aug 24, 2017

Closing for now – ongoing investigation as to whether this is a phantomjs bug in #31

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Async/Await with Vue.js Components
Vue allows any method to be an async method. Here is an example with data requested per click on a button. <button @click="loadUsers">Load ......
Read more >
Async Components - Vue.js
As you can see, defineAsyncComponent accepts a loader function that returns a Promise. The Promise's resolve callback should be called when you have...
Read more >
How to display async data in vue template - Stack Overflow
There are a few good methods of handling async data in Vue. Call a method that fetches the data in the created lifecycle...
Read more >
How to Use Async and Await with Vue.js Apps - Medium
Data will be saved to db.json of the folder that we're in, which should our app's project folder. At the end, we have...
Read more >
Async with Composition API - Anthony Fu
There is a major caveat when working with asynchronous functions in Vue Composition API, that I believe many of you have ever come...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found