Skip to content

Commit 2669347

Browse files
committed
fix: watch不生效
1 parent a8c5098 commit 2669347

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

playground/src/module/basic/simple-component/index.view.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref } from 'vue'
1+
import { ref, watch } from 'vue'
22
import { defineComponent, useClassAndStyle, type ClassAndStyleProps } from 'vue3-oop'
33

44
// region 函数组件
@@ -28,6 +28,10 @@ export const SimpleStateComponent = defineComponent(function SimpleStateComponen
2828
export const SimpleStateWithDefaultValueComponent = defineComponent(
2929
function SimpleStateWithDefaultValueComponent(props: SimpleStateComponentProps, { attrs }) {
3030
const classAndStyle = useClassAndStyle()
31+
watch(
32+
() => props.initialValue,
33+
(n, o) => console.log(555555, n, o),
34+
)
3135
const count = ref(props.initialValue || 0)
3236
return () => {
3337
console.log(2222, props.initialValue, attrs)
@@ -41,12 +45,12 @@ export const SimpleStateWithDefaultValueComponent = defineComponent(
4145
}
4246
},
4347
{
44-
props: {
45-
initialValue: {
46-
type: Number,
47-
default: 20,
48-
},
49-
},
48+
// props: {
49+
// initialValue: {
50+
// type: Number,
51+
// default: 20,
52+
// },
53+
// },
5054
},
5155
)
5256

src/simple-props/composables.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ClassAndStyleProps } from '../type'
33

44
export function camelizePropKey(p: string | symbol): string | symbol {
55
if (typeof p === 'string') {
6-
if (p.startsWith('data-')) return p
6+
if (p.startsWith('data-') || p.startsWith('aria-')) return p
77
return camelize(p)
88
}
99
return p
@@ -19,8 +19,9 @@ export function useProps<T>(): T {
1919
const getProps = () => {
2020
return Object.fromEntries(Object.entries(instance.vnode.props || {}).map(([k, v]) => [camelizePropKey(k), v]))
2121
}
22+
const attrs = useAttrs()
2223

23-
const proxy = new Proxy(
24+
return new Proxy(
2425
{},
2526
{
2627
get(target, p, receiver) {
@@ -34,7 +35,7 @@ export function useProps<T>(): T {
3435
// @ts-ignore
3536
return instance.props[key]
3637
} else {
37-
return Reflect.get(getProps(), key, receiver)
38+
return attrs[key as string] || attrs[p as string]
3839
}
3940
},
4041
ownKeys() {
@@ -63,8 +64,6 @@ export function useProps<T>(): T {
6364
},
6465
},
6566
) as any
66-
67-
return proxy
6867
}
6968

7069
function getSlotName(p: PropertyKey) {

0 commit comments

Comments
 (0)