mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-03 12:38:24 +08:00
fix: actually disable dep collection when invoking lifecycle hooks (#9095)
fix #9046
This commit is contained in:
parent
b0ccb86183
commit
0d62bb84ff
@ -55,11 +55,12 @@ export default class Dep {
|
||||
Dep.target = null
|
||||
const targetStack = []
|
||||
|
||||
export function pushTarget (_target: ?Watcher) {
|
||||
if (Dep.target) targetStack.push(Dep.target)
|
||||
Dep.target = _target
|
||||
export function pushTarget (target: ?Watcher) {
|
||||
targetStack.push(target)
|
||||
Dep.target = target
|
||||
}
|
||||
|
||||
export function popTarget () {
|
||||
Dep.target = targetStack.pop()
|
||||
targetStack.pop()
|
||||
Dep.target = targetStack[targetStack.length - 1]
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
import Dep from 'core/observer/dep'
|
||||
|
||||
describe('Instance methods lifecycle', () => {
|
||||
describe('$mount', () => {
|
||||
@ -32,6 +33,26 @@ describe('Instance methods lifecycle', () => {
|
||||
expect(vm.$el.tagName).toBe('DIV')
|
||||
expect(vm.$el.textContent).toBe('hi')
|
||||
})
|
||||
|
||||
it('Dep.target should be undefined in lifecycle', () => {
|
||||
const vm = new Vue({
|
||||
template: '<div><my-component></my-component></div>',
|
||||
components: {
|
||||
myComponent: {
|
||||
template: '<div>hi</div>',
|
||||
mounted () {
|
||||
const _msg = this.msg
|
||||
expect(Dep.target).toBe(undefined)
|
||||
},
|
||||
computed: {
|
||||
msg () {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('$destroy', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user