VueHow to communicate between components? The following article will share with you more than ten Vue3 component communication methods. I hope it will be helpful to you!
##This article explains the basic usage of various communication methods ofAs we all know, a very important knowledge point inVue 3.2
components, and uses
single file component<script setup> .
Vue.js is component communication. Whether it is the development of business classes or component library development, each has its own communication method. [Related recommendations:
vuejs video tutorial]
Vue 3.
The collection (learned) is your own!
Props
Parent component passes value to child component (abbreviation: parent to child)Props Document
https:/ /v3.cn.vuejs.org/guide/component-props.html Parent component
// Parent.vue
<template>
<!-- 使用子组件 -->
<Child :msg="message" />
</template>
<script setup>
import Child from './components/Child.vue' // 引入子组件
let message = '雷猴'
</script>
Child component
// Child.vue <template> <div> {{ msg }} </div> </template> <script setup> const props = defineProps({ msg: { type: String, default: '' } }) console.log(props.msg) // 在 js 里需要使用 props.xxx 的方式使用。在 html 中使用不需要 props </script>
<script setup> to declare
props, which has full inference and is
<script setup> is available directly.
For more details, please see
.https://v3.cn.vuejs.org/api/sfc-script-setup.html#defineprops-and-defineemits
at
Latest Articles by Author
2023-04-26 17:59:18 2023-04-26 17:47:48 2023-04-26 17:41:42 2023-04-26 17:37:05 2023-04-26 17:31:25 2023-04-26 17:27:32 2023-04-25 19:57:58 2023-04-25 19:53:11 2023-04-25 19:49:11 2023-04-25 19:41:54Latest Issues
2025-03-18 12:45:35 2025-03-18 12:44:35 2025-03-18 12:43:31 2025-03-18 12:34:33 2025-03-18 12:33:31Related TopicsMore>
The difference between vue2.0 and 3.0
What are the life cycles of vue3
What are the configuration management tools?
console.readline
freelaunchbar
How to restore IE browser to automatically jump to EDGE
What is the difference between css framework and component library
Solution to slow access speed when renting a US server
How to optimize the performance of Tomcat