网站首页 > 博客文章 正文
一 子组件
<template>
<div>
{{ msg }}
</div>
</template>
<script>
export default {
data() {
return {
msg: "hello world~~~"
}
}
}
</script>
二 父组件
<template>
<div id="app">
<!-- ref的值任意写,只是一个标识,父组件接收子组件的值的时候对应好就行了 -->
<hello-world ref="ree"></hello-world>
<button @click="getHello">获取helloworld组件中的值</button>
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld.vue";
export default {
components: {
HelloWorld
},
methods: {
getHello() {
console.log(this.$refs.ree.msg)
}
}
};
</script>
猜你喜欢
- 2024-10-04 Vue3的使用toRef和toRefs(vue torefs)
- 2024-10-04 Vue3教程 5.响应式toRef和toRefs函数
- 2024-10-04 vue3的readonly、shallowReadonly、shallowReactive、shallowRef
- 2024-10-04 全网首发:Vue3.5 源码 useTemplateRef #vue
- 2024-10-04 一起学习vue3Ts-ref全家桶(vue3.0全家桶最全入门指南)
- 2024-10-04 Vue语法之ref reactive对比及使用场景
- 2024-10-04 吃瓜!前端人因 Vue3 的 Ref 语法糖提案打起来了
- 2024-10-04 终于搞懂了!原来vue3中template使用ref无需.value是因为这个
- 2024-10-04 [Vue 3] 为什么需要同时使用Ref和Reactive
- 2024-10-04 Vue 父子组件通信 ref 与 $parent / $children
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- ifneq (61)
- 字符串长度在线 (61)
- googlecloud (64)
- messagesource (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)