+47
-2
lines changedFilter options
+47
-2
lines changed Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
3
3
import { warn } from '../util/index'
4
4
import { hasOwn } from 'shared/util'
5
5
import { hasSymbol } from 'core/util/env'
6
-
import { defineReactive } from '../observer/index'
6
+
import { defineReactive, observerState } from '../observer/index'
7
7
8
8
export function initProvide (vm: Component) {
9
9
const provide = vm.$options.provide
@@ -17,6 +17,7 @@ export function initProvide (vm: Component) {
17
17
export function initInjections (vm: Component) {
18
18
const result = resolveInject(vm.$options.inject, vm)
19
19
if (result) {
20
+
observerState.shouldConvert = false
20
21
Object.keys(result).forEach(key => {
21
22
/* istanbul ignore else */
22
23
if (process.env.NODE_ENV !== 'production') {
@@ -32,6 +33,7 @@ export function initInjections (vm: Component) {
32
33
defineReactive(vm, key, result[key])
33
34
}
34
35
})
36
+
observerState.shouldConvert = true
35
37
}
36
38
}
37
39
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1
1
import Vue from 'vue'
2
-
import { isNative } from 'core/util/env'
2
+
import { Observer } from 'core/observer/index'
3
+
import { isNative, isObject, hasOwn } from 'core/util/index'
3
4
4
5
describe('Options provide/inject', () => {
5
6
let injected
@@ -399,4 +400,46 @@ describe('Options provide/inject', () => {
399
400
400
401
expect(injected).toEqual(['foo', 'bar'])
401
402
})
403
+
404
+
// #5913
405
+
it('should keep the reactive with provide', () => {
406
+
function isObserver (obj) {
407
+
if (isObject(obj)) {
408
+
return hasOwn(obj, '__ob__') && obj.__ob__ instanceof Observer
409
+
}
410
+
return false
411
+
}
412
+
413
+
const vm = new Vue({
414
+
template: `<div><child ref='child'></child></div>`,
415
+
data () {
416
+
return {
417
+
foo: {},
418
+
$foo: {},
419
+
foo1: []
420
+
}
421
+
},
422
+
provide () {
423
+
return {
424
+
foo: this.foo,
425
+
$foo: this.$foo,
426
+
foo1: this.foo1,
427
+
bar: {},
428
+
baz: []
429
+
}
430
+
},
431
+
components: {
432
+
child: {
433
+
inject: ['foo', '$foo', 'foo1', 'bar', 'baz'],
434
+
template: `<span/>`
435
+
}
436
+
}
437
+
}).$mount()
438
+
const child = vm.$refs.child
439
+
expect(isObserver(child.foo)).toBe(true)
440
+
expect(isObserver(child.$foo)).toBe(false)
441
+
expect(isObserver(child.foo1)).toBe(true)
442
+
expect(isObserver(child.bar)).toBe(false)
443
+
expect(isObserver(child.baz)).toBe(false)
444
+
})
402
445
})
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4