This article mainly introduces the method of component communication in vue-cli. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look.
This article introduces the method of component communication in vue-cli and shares it with everyone. The details are as follows:
There are three types of communication between vue components:
1. Parent component communicates with child component
2. Child component communicates with parent component
3. Same Communication between level components
1. Parent-to-child component communication
Take app.vue as the parent component, content. vue when a child component
1.Import the subcomponent in the parent component (subcomponent export)
import contents from './components/content';
2.Register the subcomponent in the parent component
data() { return { test:'0' }; }, components:{ 'v-header':headers, 'v-content':contents }
3.Subcomponent Receive data through props
<v-content :childs='test'></v-content>
2. Communication between child and parent component
Child component:
<template> <p @click="down()"></p> </template> methods: { down() { this.$emit('down','null'); //主动触发down方法,'null'为向父组件传递的数据 } }
Parent component:
<p> <child @down="changes" :test="test"></child> //监听子组件触发的down事件,然后调用changes方法 </p> methods: { changes(msg) { this.test= test; } }
2. Non-parent-child component communication
//把a当作一个中转站 var a = new Vue();
Component 1 triggers:
<p @click="eve"></p> methods:{ eve(){ a.$emit("change",'null') } }
Component 2 receives:
<p></p> created(){ a.$on('change',()=>{ this.msg = 'null' }) }
The above is what I compiled for everyone, I hope it will be helpful to everyone in the future.
Related articles:
How to implement mobile adaptation in vue-cli
How to implement the display box in the Vue component Toast Effect
About rules parameter processing in webpack
How to implement simple calculations in AngularJS
The above is the detailed content of How to implement component communication in vue-cli. For more information, please follow other related articles on the PHP Chinese website!

Vue组件通信:使用回调函数进行组件通信在Vue应用程序中,有时候我们需要让不同的组件之间进行通信,以便它们可以共享信息和相互协作。Vue提供了多种方式来实现组件之间的通信,其中一种常用的方式是使用回调函数。回调函数是一种将一个函数作为参数传递给另一个函数并在特定事件发生时被调用的机制。在Vue中,我们可以利用回调函数来实现组件之间的通信,使得一个组件可以在

Vue和Vue-Router:如何在组件之间共享数据?简介:Vue是一个流行的JavaScript框架,用于构建用户界面。Vue-Router是Vue的官方路由管理器,用于实现单页面应用。在Vue应用中,组件是构建用户界面的基本单位。在许多情况下,我们需要在不同的组件之间共享数据。本文将介绍一些方法,帮助你在Vue和Vue-Router中实现数据共享,以及

数据通信中的信道传输速率单位是bps,它表示“位/秒”或“比特/秒”,即数据传输速率在数值上等于每秒钟传输构成数据代码的二进制比特数,也称“比特率”。比特率表示单位时间内传送比特的数目,用于衡量数字信息的传送速度;根据每帧图像存储时所占的比特数和传输比特率,可以计算数字图像信息传输的速度。

在我们写 vue3 的项目中,我们都会进行组件通信,我们除了使用 pinia 公共数据源的方式除外,我们还可采用那些更简单的API方法呢?那下面我就来给大家介绍介绍几种父子组件和子父组件通信的方式。

Angular组件间怎么通信?下面本篇文章带大家了解一下Angular中组件通信的方法,希望对大家有所帮助!

Vue组件通讯中的事件总线方案比较在Vue开发中,组件之间的通讯是一项重要的任务。Vue提供了多种方式来实现组件之间的通讯,其中之一就是通过事件总线。本文将对Vue组件通讯中的事件总线方案进行比较,并给出相应的代码示例。使用自定义事件Vue提供了$emit和$on方法来实现自定义事件的触发和监听。下面是一个简单的示例://Bus.js

Vue组件通信:使用v-pre指令进行跳过编译通信Vue是一种流行的JavaScript框架,用于构建用户界面。在Vue中,组件是构建界面的基本单元。组件间通信是Vue开发中常见的需求,通常使用props和events来实现。然而,有时候我们可能希望在组件之间进行一种特殊的通信方式,即跳过编译的通信。这种通信方式可以用v-pre指令来实现。本文将介绍如何使用

Vue是一种流行的前端框架,它的灵活性和易用性受到了许多开发者的青睐。为了更好的开发Vue应用程序,Vue团队开发了一个强大的工具-Vue-cli,使得开发Vue应用程序变得更加容易。本文将为您详细介绍Vue-cli的使用方法。一、安装Vue-cli使用Vue-cli之前,需要先安装它。首先,您需要确保已经安装了Node.js。然后,使用npm安装Vue-c


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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.

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

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),