mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(vue-app): empty $fetch
function for SSR with static target (#8053)
This commit is contained in:
parent
b93ba5c688
commit
45b7838710
@ -41,6 +41,8 @@ export default {
|
|||||||
this._fetchOnServer = this.$options.fetchOnServer !== false
|
this._fetchOnServer = this.$options.fetchOnServer !== false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Added for remove vue undefined warning while ssr
|
||||||
|
this.$fetch = () => {} // issue #8043
|
||||||
Vue.util.defineReactive(this, '$fetchState', {
|
Vue.util.defineReactive(this, '$fetchState', {
|
||||||
pending: true,
|
pending: true,
|
||||||
error: null,
|
error: null,
|
||||||
|
@ -76,6 +76,12 @@ describe('basic browser', () => {
|
|||||||
expect(await page.$text('pre')).toContain('kevinmarrec')
|
expect(await page.$text('pre')).toContain('kevinmarrec')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('ssr: /fetch-root', async () => {
|
||||||
|
const page = await browser.page(url('/fetch-root'))
|
||||||
|
expect(await page.$text('button')).toContain('has fetch')
|
||||||
|
page.close()
|
||||||
|
})
|
||||||
|
|
||||||
test('ssr: /fetch-client', async () => {
|
test('ssr: /fetch-client', async () => {
|
||||||
const page = await browser.page(url('/fetch-client'))
|
const page = await browser.page(url('/fetch-client'))
|
||||||
expect(await page.$text('p')).toContain('Fetching...')
|
expect(await page.$text('p')).toContain('Fetching...')
|
||||||
|
5
test/fixtures/fetch/layouts/default.vue
vendored
5
test/fixtures/fetch/layouts/default.vue
vendored
@ -31,6 +31,11 @@
|
|||||||
Fetch button
|
Fetch button
|
||||||
</n-link>
|
</n-link>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<n-link to="/fetch-root">
|
||||||
|
Fetch in root click handler
|
||||||
|
</n-link>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<n-link to="/fetch-component">
|
<n-link to="/fetch-component">
|
||||||
Fetch in component
|
Fetch in component
|
||||||
|
21
test/fixtures/fetch/pages/fetch-root.vue
vendored
Normal file
21
test/fixtures/fetch/pages/fetch-root.vue
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<template>
|
||||||
|
<button @click="$fetch">
|
||||||
|
fetch {{ foo }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
async fetch () {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
|
|
||||||
|
this.foo = this.$fetch ? 'has fetch' : 'hasn\'t fetch'
|
||||||
|
},
|
||||||
|
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
foo: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user