Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commitfa61c00

Browse files
committed
fix proxy missing property detection when render function does not usewith
1 parent1a7b910 commitfa61c00

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

‎src/core/instance/proxy.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ if (process.env.NODE_ENV !== 'production') {
1212
'require'// for Webpack/Browserify
1313
)
1414

15+
constwarnNonPresent=(target,key)=>{
16+
warn(
17+
`Property or method "${key}" is not defined on the instance but `+
18+
`referenced during render. Make sure to declare reactive data `+
19+
`properties in the data option.`,
20+
target
21+
)
22+
}
23+
1524
hasProxy=
1625
typeofProxy!=='undefined'&&
1726
Proxy.toString().match(/nativecode/)
@@ -21,14 +30,16 @@ if (process.env.NODE_ENV !== 'production') {
2130
consthas=keyintarget
2231
constisAllowed=allowedGlobals(key)||key.charAt(0)==='_'
2332
if(!has&&!isAllowed){
24-
warn(
25-
`Property or method "${key}" is not defined on the instance but `+
26-
`referenced during render. Make sure to declare reactive data `+
27-
`properties in the data option.`,
28-
target
29-
)
33+
warnNonPresent(target,key)
3034
}
3135
returnhas||!isAllowed
36+
},
37+
38+
get(target,key){
39+
if(typeofkey==='string'&&!(keyintarget)){
40+
warnNonPresent(target,key)
41+
}
42+
returntarget[key]
3243
}
3344
}
3445

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importVuefrom'vue'
2+
3+
if(typeofProxy!=='undefined'){
4+
describe('render proxy',()=>{
5+
it('should warn missing property in render fns with `with`',()=>{
6+
newVue({
7+
template:`<div>{{ a }}</div>`
8+
}).$mount()
9+
expect(`Property or method "a" is not defined`).toHaveBeenWarned()
10+
})
11+
12+
it('should warn missing property in render fns without `with`',()=>{
13+
newVue({
14+
render(h){
15+
returnh('div',[this.a])
16+
}
17+
}).$mount()
18+
expect(`Property or method "a" is not defined`).toHaveBeenWarned()
19+
})
20+
})
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp