search
HomeWeb Front-endVue.jsHow to communicate between Vue3 components? 10+ communication methods to share

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!

How to communicate between Vue3 components? 10+ communication methods to share

##This article explains the basic usage of various communication methods of

Vue 3.2 components, and uses single file component

As we all know, a very important knowledge point in

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]

This article is suitable for:

  • Readers who have a basic knowledge of

    Vue 3.

  • Readers who plan to develop component libraries.

Knowledge points covered in this article:

  • Props

  • ##emits
  • expose / ref
  • Non-Props
  • v-model
  • slot
  • provide / inject
  • bus
  • getCurrentInstance
  • Vuex
  • Pinia
  • ##mitt.js
  • I will write a simple demo for all the knowledge points listed above. The purpose of this article is to let everyone know that these methods can be used, so it does not delve into every knowledge point.
It is recommended that readers follow this article to type the code, and then dig into various knowledge points according to the links given in this article.

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 &#39;./components/Child.vue&#39; // 引入子组件

let message = &#39;雷猴&#39;
</script>

Child component

// Child.vue

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script setup>

const props = defineProps({
  msg: {
    type: String,
    default: &#39;&#39;
  }
})

console.log(props.msg) // 在 js 里需要使用 props.xxx 的方式使用。在 html 中使用不需要 props

</script>
The defineProps

API must be used in

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.