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

Commit6893499

Browse files
committed
feat: rename inject alias from "name" to "from"
1 parent6dac3db commit6893499

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

‎src/core/instance/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function resolveInject (inject: any, vm: Component): ?Object {
4949

5050
for(leti=0;i<keys.length;i++){
5151
constkey=keys[i]
52-
constprovideKey=inject[key].name
52+
constprovideKey=inject[key].from
5353
letsource=vm
5454
while(source){
5555
if(source._provided&&provideKeyinsource._provided){

‎src/core/util/options.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ function normalizeInject (options: Object) {
273273
constnormalized=options.inject={}
274274
if(Array.isArray(inject)){
275275
for(leti=0;i<inject.length;i++){
276-
normalized[inject[i]]={name:inject[i]}
276+
normalized[inject[i]]={from:inject[i]}
277277
}
278278
}elseif(isPlainObject(inject)){
279279
for(constkeyininject){
280280
constval=inject[key]
281281
normalized[key]=isPlainObject(val)
282-
?extend({name:key},val)
283-
:{name:val}
282+
?extend({from:key},val)
283+
:{from:val}
284284
}
285285
}
286286
}

‎test/unit/features/options/inject.spec.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,29 @@ describe('Options provide/inject', () => {
384384
injected=[this.foo,this.bar,this.baz]
385385
}
386386
})
387-
expect(`Injection "foo" not found`).not.toHaveBeenWarned()
388-
expect(`Injection "bar" not found`).not.toHaveBeenWarned()
389-
expect(`Injection "baz" not found`).not.toHaveBeenWarned()
390387
expect(injected).toEqual([1,false,undefined])
391388
})
392389

390+
it('should support name alias and default together',()=>{
391+
constvm=newVue({
392+
provide:{
393+
FOO:2
394+
}
395+
})
396+
newVue({
397+
parent:vm,
398+
inject:{
399+
foo:{from:'FOO',default:1},
400+
bar:{default:false},
401+
baz:{default:undefined}
402+
},
403+
created(){
404+
injected=[this.foo,this.bar,this.baz]
405+
}
406+
})
407+
expect(injected).toEqual([2,false,undefined])
408+
})
409+
393410
it('should use provided value even if inject has default',()=>{
394411
constvm=newVue({
395412
provide:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp