Skip to content

Commit

Permalink
feat: set instance.props to readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Mar 5, 2021
1 parent 15d7ab7 commit 9534e47
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/runtime-core/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { initSlots } from "./componentSlots";
import { emit } from "./componentEmits";
import { PublicInstanceProxyHandlers } from "./componentPublicInstance";
import { proxyRefs } from "@vue/reactivity";
import { shallowReadonly } from "@vue/reactivity";
export function createComponentInstance(vnode, parent) {
const instance = {
type: vnode.type,
Expand Down Expand Up @@ -71,7 +72,9 @@ function setupStatefulComponent(instance) {
setCurrentInstance(instance);

const setupContext = createSetupContext(instance);
const setupResult = setup && setup(instance.props, setupContext);
// 真实的处理场景里面应该是只在 dev 环境才会把 props 设置为只读的
const setupResult =
setup && setup(shallowReadonly(instance.props), setupContext);

setCurrentInstance(null);

Expand Down

0 comments on commit 9534e47

Please sign in to comment.