Detailed explanation of Vue component parent-child communication (1)
This article mainly introduces the detailed explanation of the communication between the parent and the child of the Vue component and the realization of the login window. It has a certain reference value. Interested friends can refer to it. I hope it can help everyone.
1. Communication between components (parent component --> child component)
Steps:
①Parent component Pass the value when calling the child component
<child-component myValue="123"> </child-component>
②Get the value passed by the parent component in the child component
Vue.component('child-component',{ props:['myValue'], template:'' })
Code 1:
##
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>父传子</title> <script src="js/vue.js"></script> </head> <body> <p id="container"> <p>{{msg}}</p> <parent-component></parent-component> </p> <script> // 在vue中一切都是组件 //父传子 Vue.component("parent-component",{ data:function(){ return { gift:"传家宝" } }, template:` <p> <h1>这是父组件</h1> <hr> <child-component v-bind:myValue="gift"></child-component> </p> ` }) Vue.component("child-component",{ props:["myValue"], template:` <p> <h1>这是子组件</h1> <p>{{"父传递的值:"+myValue}}</p> </p> ` }) new Vue({ el:"#container", data:{ msg:"Hello VueJs" } }) </script> </body> </html>
props is a property attribute, which is an array
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>父子之间通信练习</title> <script src="js/vue.js"></script> </head> <body> <p id="container"> <p>{{msg}}</p> <my-login></my-login> </p> <script> /* 登录窗口 创建4个组件,分别是my-label my-input my-button my-login(复合组件) */ Vue.component("my-label",{ props:["myLabel"], template:` <p> <label>{{myLabel}}</label> </p> ` }) Vue.component("my-input",{ template:` <p> <input type="text"/> </p> ` }) Vue.component("my-button",{ props:["myButton"], template:` <p> <button>{{myButton}}</button> </p> ` }) //复合组件 Vue.component("my-login",{ data:function(){ return { uname:"用户名", upwd:"密码", login:"登录", register:"注册" } }, template:` <p> <my-label v-bind:myLabel="uname"></my-label> <my-input></my-input> <my-label v-bind:myLabel="upwd"></my-label> <my-input></my-input> <my-button v-bind:myButton="login"></my-button> <my-button v-bind:myButton="register"></my-button> </p> ` }) new Vue({ el:"#container", data:{ msg:"Hello VueJs" } }) </script> </body> </html>
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <script src="js/vue.js"></script> <title></title> </head> <body> <p id="container"> <my-login></my-login> </p> <script> Vue.component('my-label',{ props:['labelName'], template:'<label>{{labelName}}</label>' }) Vue.component('my-input',{ props:['tips'], template:'<input type="text" :placeholder="tips"/>' }) Vue.component('my-button',{ props:['btnName'], template:'<button>{{btnName}}</button>' }) Vue.component('my-login',{ template:` <form> <my-label labelName="用户名"></my-label> <my-input tips="请输入用户名"></my-input> <br/> <my-label labelName="密码"></my-label> <my-input tips="请输入密码"></my-input> <br/> <my-button btnName="登录"></my-button> <my-button btnName="注册"></my-button> </form> ` }) new Vue({ el: '#container', data: { msg: 'Hello Vue' } }) </script> </body> </html>
Introduction to the storage event of the communication method between js pages
Vue.js component communication Detailed analysis of several postures
A brief introduction to the communication methods between React components
The above is the detailed content of Detailed explanation of Vue component parent-child communication (1). For more information, please follow other related articles on the PHP Chinese website!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In the previous article (link), Xiao Zaojun introduced the development history of broadband technology from ISDN, xDSL to 10GPON. Today, let’s talk about the upcoming new generation of optical fiber broadband technology-50GPON. █F5G and F5G-A Before introducing 50GPON, let’s talk about F5G and F5G-A. In February 2020, ETSI (European Telecommunications Standards Institute) promoted a fixed communication network technology system based on 10GPON+FTTR, Wi-Fi6, 200G optical transmission/aggregation, OXC and other technologies, and named it F5G. That is, the fifth generation fixed network communication technology (The5thgenerationFixednetworks). F5G is a fixed network

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.

Original title: "How does a wireless mouse become wireless?" 》Wireless mice have gradually become a standard feature of today’s office computers. From now on, we no longer have to drag long cords around. But, how does a wireless mouse work? Today we will learn about the development history of the No.1 wireless mouse. Did you know that the wireless mouse is now 40 years old? In 1984, Logitech developed the world's first wireless mouse, but this wireless mouse used infrared as a The signal carrier is said to look like the picture below, but later failed due to performance reasons. It was not until ten years later in 1994 that Logitech finally successfully developed a wireless mouse that works at 27MHz. This 27MHz frequency also became the wireless mouse for a long time.

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

In today's digital age, broadband has become a necessity for each of us and every family. Without it, we would be restless and restless. So, do you know the technical principles behind broadband? From the earliest 56k "cat" dial-up to the current Gigabit cities and Gigabit homes, what kind of changes has our broadband technology experienced? In today’s article, let’s take a closer look at the “Broadband Story”. Have you seen this interface between █xDSL and ISDN? I believe that many friends born in the 70s and 80s must have seen it and are very familiar with it. That's right, this was the interface for "dial-up" when we first came into contact with the Internet. That was more than 20 years ago, when Xiao Zaojun was still in college. In order to surf the Internet, I

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions
