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
/vuePublic

Commit08382f0

Browse files
committed
fix(props): should not unwrap props that are raw refs
close#12930
1 parent947993f commit08382f0

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

‎src/core/instance/state.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,25 @@ function initProps(vm: Component, propsOptions: Object) {
9595
vm
9696
)
9797
}
98-
defineReactive(props,key,value,()=>{
99-
if(!isRoot&&!isUpdatingChildComponent){
100-
warn(
101-
`Avoid mutating a prop directly since the value will be `+
102-
`overwritten whenever the parent component re-renders. `+
103-
`Instead, use a data or computed property based on the prop's `+
104-
`value. Prop being mutated: "${key}"`,
105-
vm
106-
)
107-
}
108-
})
98+
defineReactive(
99+
props,
100+
key,
101+
value,
102+
()=>{
103+
if(!isRoot&&!isUpdatingChildComponent){
104+
warn(
105+
`Avoid mutating a prop directly since the value will be `+
106+
`overwritten whenever the parent component re-renders. `+
107+
`Instead, use a data or computed property based on the prop's `+
108+
`value. Prop being mutated: "${key}"`,
109+
vm
110+
)
111+
}
112+
},
113+
true
114+
)
109115
}else{
110-
defineReactive(props,key,value)
116+
defineReactive(props,key,value,undefined,true)
111117
}
112118
// static props are already proxied on the component's prototype
113119
// during Vue.extend(). We only need to proxy props defined at

‎test/unit/features/options/props.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
importVuefrom'vue'
22
import{hasSymbol}from'core/util/env'
33
importtestObjectOptionfrom'../../../helpers/test-object-option'
4+
import{ref}from'v3'
45

56
describe('Options props',()=>{
67
testObjectOption('props')
@@ -593,4 +594,21 @@ describe('Options props', () => {
593594
'Invalid prop type: "String" is not a constructor'
594595
).toHaveBeenWarned()
595596
})
597+
598+
// #12930
599+
it('should not unwrap prop values that are raw refs',()=>{
600+
letval
601+
constComp={
602+
props:['msg'],
603+
created(){
604+
val=this.msg
605+
},
606+
render(){}
607+
}
608+
constr=ref()
609+
newVue({
610+
render:h=>h(Comp,{props:{msg:r}})
611+
}).$mount()
612+
expect(val).toBe(r)
613+
})
596614
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp