fix(vue-app): align client fetch key with server (#8809)

This commit is contained in:
Daniel Roe 2021-02-12 11:55:27 +00:00 committed by GitHub
parent 9c24c110b6
commit e277bb284b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -72,7 +72,7 @@ function createdFullStatic() {
this._fetchKey = this.$options.fetchKey.call(this, getCounter)
} else {
const key = 'string' === typeof this.$options.fetchKey ? this.$options.fetchKey : defaultKey
this._fetchKey = key + ':' + getCounter(key)
this._fetchKey = key ? key + ':' + getCounter(key) : String(getCounter(key))
}
const data = this.<%= globals.nuxt %>._pagePayload.fetch[this._fetchKey]

View File

@ -54,7 +54,7 @@ export default {
this._fetchKey = this.$options.fetchKey.call(this, getCounter)
} else {
const key = 'string' === typeof this.$options.fetchKey ? this.$options.fetchKey : defaultKey
this._fetchKey = key + getCounter(key)
this._fetchKey = key ? key + ':' + getCounter(key) : String(getCounter(key))
}
// Added for remove vue undefined warning while ssr

View File

@ -81,7 +81,7 @@ describe('basic browser', () => {
const fetchKeys = await page.evaluate(() => Object.keys(window.__NUXT__.fetch))
expect(fetchKeys).toEqual([
'0',
'DefaultLayout0'
'DefaultLayout:0'
])
expect(await page.$text('div')).toContain('foo-bar-baz')
expect(await page.$text('div')).toContain('fizz-buzz')
@ -95,7 +95,7 @@ describe('basic browser', () => {
const fetchKeys = await page.evaluate(() => Object.keys(window.__NUXT__.fetch))
expect(fetchKeys).toEqual([
'0',
'DefaultLayout0'
'DefaultLayout:0'
])
expect(await page.$text('div')).toContain('foo-bar-baz')
expect(await page.$text('div')).toContain('fizz-buzz')
@ -108,7 +108,7 @@ describe('basic browser', () => {
const fetchKeys = await page.evaluate(() => Object.keys(window.__NUXT__.fetch))
expect(fetchKeys).toEqual([
'0',
'DefaultLayout0',
'DefaultLayout:0',
'ie0'
])
expect(await page.$text('button')).toContain('has fetch')
@ -120,10 +120,10 @@ describe('basic browser', () => {
const fetchKeys = await page.evaluate(() => Object.keys(window.__NUXT__.fetch))
expect(fetchKeys).toEqual([
'0',
'DefaultLayout0',
'team0'
'DefaultLayout:0',
'team:0'
])
const team = await page.evaluate(() => window.__NUXT__.fetch.team0.team)
const team = await page.evaluate(() => window.__NUXT__.fetch['team:0'].team)
expect(team.includes('Atinux'))
expect(await page.$text('div')).toContain('foo-bar-baz')
expect(await page.$text('div')).toContain('fizz-buzz')