Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xavier-萧
VueJS-生命周期钩子
提交
e477716a
V
VueJS-生命周期钩子
项目概览
Xavier-萧
/
VueJS-生命周期钩子
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VueJS-生命周期钩子
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e477716a
编写于
7月 03, 2024
作者:
B
big_sun_962464
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Wed Jul 3 15:51:00 CST 2024 inscode
上级
329fe894
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
114 addition
and
70 deletion
+114
-70
src/App.vue
src/App.vue
+42
-40
src/components/Com.vue
src/components/Com.vue
+0
-30
src/components/Com1.vue
src/components/Com1.vue
+25
-0
src/components/Com2.vue
src/components/Com2.vue
+47
-0
未找到文件。
src/App.vue
浏览文件 @
e477716a
<
script
setup
>
<
script
setup
>
import
Com
from
'
./components/Com.vue
'
import
Com1
from
'
./components/Com1.vue
'
import
{
onMounted
,
toRefs
,
watchEffect
,
shallowReadonly
,
readonly
,
ref
,
reactive
,
shallowRef
,
computed
,
isRef
,
unref
,
toRef
,
toValue
,
watch
}
from
'
vue
'
import
Com2
from
'
./components/Com2.vue
'
import
{
onMounted
,
toRefs
,
watchEffect
,
shallowReadonly
,
readonly
,
ref
,
reactive
,
shallowRef
,
computed
,
isRef
,
unref
,
toRef
,
toValue
,
watch
,
onBeforeMount
,
onBeforeUpdate
,
onUpdated
}
from
'
vue
'
onMounted
(()
=>
{
// onBeforeMount(()=>{
// debugger
})
// console.log('onBeforeMount')
// })
// onMounted(()=>{
// debugger
// console.log('onMounted')
// })
// onBeforeUpdate(()=>{
// debugger
// console.log('onBeforeUpdate')
// })
// onUpdated(()=>{
// debugger
// console.log('onUpdated')
// })
const
obj
=
{
const
obj
=
{
name
:
'
普通obj
'
name
:
'
普通obj
'
}
}
// const name = toRef(obj.name)
const
refMsg
=
ref
(
"
欢迎使用VUE3.0
"
)
const
name1
=
toRef
(()
=>
obj
.
name
)
const
refMsg
=
ref
(
"
欢迎使用VUE3.0
"
)
const
refObj
=
ref
({
msg
:
'
refObj-欢迎使用VUE3.0
'
,
val
:
12
})
const
reactiveMsg
=
reactive
(
"
欢迎使用VUE
"
)
const
refCom
=
ref
({
const
reactiveObj
=
reactive
({
name
:
'
Com1
'
,
msg
:
'
reactiveObj-欢迎使用VUE
'
,
com
:
Com1
val
:
77
})
})
// const msg = toRef(reactiveObj,'msg')
function
changeMsg
(){
// const msg = ref("欢迎使用VUE3.0")
refMsg
.
value
=
777
function
handleClick
(){
}
const
refsObj
=
toRefs
(
reactiveObj
)
console
.
log
(
111
,
refsObj
)
function
changeMsg
(
val
){
// reactiveObj.msg=111
refsObj
.
msg
.
value
=
222
}
}
function
useFeature
(
id
){
function
useFeature
(
id
){
watch
(
watch
(
()
=>
toValue
(
id
),
()
=>
toValue
(
id
),
...
@@ -45,22 +43,26 @@ function useFeature(id){
...
@@ -45,22 +43,26 @@ function useFeature(id){
}
}
)
)
}
}
function
changeCom
(){
if
(
refCom
.
value
.
name
===
'
Com1
'
){
refCom
.
value
.
name
=
'
Com2
'
refCom
.
value
.
com
=
Com2
}
else
{
refCom
.
value
.
name
=
'
Com1
'
refCom
.
value
.
com
=
Com1
}
}
useFeature
(
refMsg
)
useFeature
(
refMsg
)
</
script
>
</
script
>
<
template
>
<
template
>
<p>
{{
refMsg
}}
</p>
<button
@
click=
"changeMsg"
>
++
</button>
<button
@
click=
"changeMsg"
>
++
</button>
<p>
{{
reactiveObj
}}
</p>
<p>
<p>
{{
refsObj
}}
</p>
<button
@
click=
"changeCom"
>
+-
</button>
<Com
v-model:msg=
"refMsg"
/>
</p>
<!--
<div>
<component
:is=
"refCom.com"
></component>
<p>
{{
obj
}}
</p>
<p>
{{
msg
}}
</p>
<p>
{{
refMsg
}}
</p>
<p>
{{
refObj
}}
</p>
<p>
{{
reactiveMsg
}}
</p>
<p>
{{
reactiveObj
}}
</p>
</div>
-->
</
template
>
</
template
>
<
style
scoped
>
<
style
scoped
>
...
...
src/components/Com.vue
已删除
100644 → 0
浏览文件 @
329fe894
<
template
>
<div>
<h2
@
click=
"handle"
>
com1
</h2>
<p>
{{
props
.
msg
}}
</p>
</div>
</
template
>
<
script
setup
lang=
"ts"
>
import
{
defineProps
,
computed
,
defineEmits
}
from
'
vue
'
const
props
=
defineProps
({
msg
:{
type
:
String
}
})
const
emits
=
defineEmits
([
'
update:msg
'
])
console
.
log
(
12
,
props
)
const
msg
=
computed
({
get
(){
return
props
.
msg
},
set
(
val
){
console
.
log
(
val
)
emits
(
'
update:msg
'
,
val
)
}
})
function
handle
(){
msg
.
value
=
'
123
'
}
</
script
>
\ No newline at end of file
src/components/Com1.vue
0 → 100644
浏览文件 @
e477716a
<
template
>
<div>
<h2>
Com1
</h2>
</div>
</
template
>
<
script
setup
lang=
"ts"
>
import
{
defineProps
,
computed
,
defineEmits
,
onActivated
,
onDeactivated
,
onBeforeUnmount
,
onUnmounted
}
from
'
vue
'
onActivated
(()
=>
{
debugger
console
.
log
(
'
Com1-onActivated
'
)
})
onDeactivated
(()
=>
{
debugger
console
.
log
(
'
Com1-onDeactivated
'
)
})
onBeforeUnmount
(()
=>
{
debugger
console
.
log
(
'
Com1-onBeforeUnmount
'
)
})
onUnmounted
(()
=>
{
debugger
console
.
log
(
'
Com1-onUnmounted
'
)
})
</
script
>
\ No newline at end of file
src/components/Com2.vue
0 → 100644
浏览文件 @
e477716a
<
template
>
<div>
<h2>
Com2-
{{
msg
}}
</h2>
<button
@
click=
"msg+='1'"
>
changeMsg
</button>
</div>
</
template
>
<
script
setup
lang=
"ts"
>
import
{
ref
,
defineProps
,
computed
,
defineEmits
,
onActivated
,
onDeactivated
,
onBeforeUnmount
,
onUnmounted
,
onBeforeMount
,
onMounted
,
onBeforeUpdate
,
onUpdated
}
from
'
vue
'
const
msg
=
ref
(
'
欢迎使用Vue
'
)
debugger
onBeforeMount
(()
=>
{
debugger
console
.
log
(
'
Com2-onBeforeMount
'
)
})
onMounted
(()
=>
{
debugger
console
.
log
(
'
Com2-onMounted
'
)
})
onBeforeUpdate
(()
=>
{
debugger
console
.
log
(
'
Com2-onBeforeUpdate
'
)
})
onUpdated
(()
=>
{
debugger
console
.
log
(
'
Com2-onUpdated
'
)
})
onActivated
(()
=>
{
debugger
console
.
log
(
'
Com2-onActivated
'
)
})
onDeactivated
(()
=>
{
debugger
console
.
log
(
'
Com2-onDeactivated
'
)
})
onBeforeUnmount
(()
=>
{
debugger
console
.
log
(
'
Com2-onBeforeUnmount
'
)
})
onUnmounted
(()
=>
{
debugger
console
.
log
(
'
Com2-onUnmounted
'
)
})
</
script
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录