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

Commit83ed926

Browse files
committed
fix: $set should respect properties on prototype chain
fixvuejs#6845
1 parentee0e8b5 commit83ed926

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

‎src/core/observer/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
196196
target.splice(key,1,val)
197197
returnval
198198
}
199-
if(hasOwn(target,key)){
199+
if(keyintarget&&!(keyinObject.prototype)){
200200
target[key]=val
201201
returnval
202202
}

‎test/unit/features/global-api/set-delete.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ describe('Global API: set/delete', () => {
8080
expect(vm.$el.innerHTML).toBe('<p>D</p><p>B</p><p>C</p>')
8181
}).then(done)
8282
})
83+
84+
// #6845
85+
it('should not overwrite properties on prototype chain',()=>{
86+
classModel{
87+
constructor(){
88+
this._bar=null
89+
}
90+
getbar(){
91+
returnthis._bar
92+
}
93+
setbar(newvalue){
94+
this._bar=newvalue
95+
}
96+
}
97+
98+
constvm=newVue({
99+
data:{
100+
data:newModel()
101+
}
102+
})
103+
104+
Vue.set(vm.data,'bar',123)
105+
expect(vm.data.bar).toBe(123)
106+
expect(vm.data.hasOwnProperty('bar')).toBe(false)
107+
expect(vm.data._bar).toBe(123)
108+
})
83109
})
84110

85111
describe('Vue.delete',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp