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

Commita64ff19

Browse files
haoqunjiangyyx990803
authored andcommitted
fix(lifecycle): updated should not be called after component being destroyed (vuejs#8381)
fixvuejs#8076
1 parenta71853b commita64ff19

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

‎src/core/observer/scheduler.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function callUpdatedHooks (queue) {
9898
while(i--){
9999
constwatcher=queue[i]
100100
constvm=watcher.vm
101-
if(vm._watcher===watcher&&vm._isMounted){
101+
if(vm._watcher===watcher&&vm._isMounted&&!vm._isDestroyed){
102102
callHook(vm,'updated')
103103
}
104104
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,43 @@ describe('Options lifecycle hooks', () => {
199199
expect(calls).toEqual(['child','parent'])
200200
}).then(done)
201201
})
202+
203+
// #8076
204+
it('should not be called after destroy',done=>{
205+
constupdated=jasmine.createSpy('updated')
206+
constdestroyed=jasmine.createSpy('destroyed')
207+
208+
Vue.component('todo',{
209+
template:'<div>{{todo.done}}</div>',
210+
props:['todo'],
211+
destroyed,
212+
updated
213+
})
214+
215+
constvm=newVue({
216+
template:`
217+
<div>
218+
<todo v-for="t in pendingTodos" :todo="t" :key="t.id"></todo>
219+
</div>
220+
`,
221+
data(){
222+
return{
223+
todos:[{id:1,done:false}]
224+
}
225+
},
226+
computed:{
227+
pendingTodos(){
228+
returnthis.todos.filter(t=>!t.done)
229+
}
230+
}
231+
}).$mount()
232+
233+
vm.todos[0].done=true
234+
waitForUpdate(()=>{
235+
expect(destroyed).toHaveBeenCalled()
236+
expect(updated).not.toHaveBeenCalled()
237+
}).then(done)
238+
})
202239
})
203240

204241
describe('beforeDestroy',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp