Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/lazy-loading-before-mount/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Home = { template: '<div>Home</div>' }
const Foo = () =>
new Promise(resolve => {
setTimeout(() =>
resolve({
template: `<div class="foo">This is Foo</div>`
})
, 10)
})

const router = new VueRouter({
mode: 'history',
base: __dirname,
routes: [
{ path: '/', component: Home },
// Just use them normally in the route config
{ path: '/async', component: Foo }
]
})

router.push('/async')

document.getElementById('load-button').addEventListener('click', (event) => {
new Vue({
router,
template: `
<div id="app">
<h1>Async</h1>
<router-view class="view"></router-view>
</div>
`
}).$mount('#app')
event.target.remove()
})
8 changes: 8 additions & 0 deletions examples/lazy-loading-before-mount/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<link rel="stylesheet" href="/global.css">
<a href="/">&larr; Examples index</a>
<div id="app"></div>

<button id="load-button">Load</button>
<script src="/__build__/shared.chunk.js"></script>
<script src="/__build__/lazy-loading-before-mount.js"></script>
2 changes: 1 addition & 1 deletion src/util/resolve-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function resolveAsyncComponents (matched: Array<RouteRecord>): Function {
match.components[key] = resolvedDef
pending--
if (pending <= 0) {
next()
next(to)
}
})

Expand Down
11 changes: 11 additions & 0 deletions test/e2e/specs/lazy-loading-before-mount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
'lazy loading before mount': function (browser) {
browser
.url('http://localhost:8080/lazy-loading-before-mount/')
// wait for the Foo component to be resolved
.click('#load-button')
.waitForElementVisible('.foo', 1000)
.assert.containsText('.view', 'This is Foo')
.end()
}
}