File tree 1 file changed +11
-12
lines changed
src/views/useradmin/refSyntax
1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
// import { useMouse } from '@vueuse/core';
3
- // import { ref } from 'vue';
4
- import { $ref } from ' vue/macros' ;
3
+ import { ref , toRaw } from ' vue' ;
5
4
6
- let stem = $ ref (' admin' );
5
+ let stem = ref (' admin' );
7
6
8
- // 公共方法里面使用$ref导出ref
7
+ // 公共方法里面使用ref导出ref
9
8
function useMouse() {
10
- let x = $ ref (0 );
11
- let y = $ ref (0 );
9
+ let x = ref (0 );
10
+ let y = ref (0 );
12
11
// 如果直接导出x,y会被识别{x.value,y.value}这样就会使出ref响应式,使用$$()可以保持响应式相当于{x:ref(0),y:ref(0)}
13
- return $$ ( {
12
+ return {
14
13
x ,
15
14
y ,
16
- }) ;
15
+ };
17
16
}
18
17
19
18
// 通过
20
- let { x, y } = $ (useMouse ());
19
+ let { x, y } = toRaw (useMouse ());
21
20
console .log (x );
22
- // // $ ref解构方法返回的ref
21
+ // // ref解构方法返回的ref
23
22
// const { x, y } = $(useMouse());
24
23
// console.log(x, y);
25
24
26
25
const updateStem = () => {
27
- stem = ' update' ;
28
- x = 200 ;
26
+ stem . value = ' update' ;
27
+ x . value = 200 ;
29
28
};
30
29
</script >
31
30
You can’t perform that action at this time.
0 commit comments