vue3 父子组件间的传值通信
1.父转子
// 父组件{{ count }}
// 子组件{{ countFa }}
2.子传父
// 父组件{{ count }}
// 子组件{{ count }}
3.父组件调用子组件方法
// 父组件{{ count }}
// 子组件{{ count }}
你可以通过在生命周期钩子前面加上 “on” 来访问组件的生命周期钩子。
下表包含如何在 setup () 内部调用生命周期钩子:
beforeCreate -> setup()
created -> setup()
beforeMount -> onBeforeMount
mounted -> onMounted
beforeUpdate -> onBeforeUpdate
updated -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed -> onUnmounted
activated -> onActivated
deactivated -> onDeactivated
errorCaptured -> onErrorCaptured
模板Refs
通过ref()函数还可以引用页面上的元素或组件
使用步骤:
1、在setup()中创建一个ref对象并返回它
2、在页面上为元素添加ref属性,并设置属性值与创建的ref对象的名称相同
3、当页面渲染完成后,可以通过该ref独享获取到页面中对应的DOM元素
链接:https://github.com/mtdream/learningV3