This article will take you to continue learningVue, and introduce in detail the life cycle and data sharing in the essential knowledge for getting started with Vue. I hope it will be helpful to everyone!
1. Component life cycle
##1.1 Life cycle & life cycle function
1️⃣ Life Cycle refers to the entire stage of a component fromcreation → running → destruction , emphasizes a time period . (Learning video sharing: vue video tutorial)
2️⃣ Life cycle function: It is abuilt-in function provided by the vue framework, which will accompany the life cycle of the component, Automatically execute in order.
? Warm reminder?:Life cycle emphasizes time period, lifecycle function emphasizes time point.
1.2 Classification of component life cycle functions
1.3 Life cycle diagram Indication
You can refer to the "life cycle diagram" given in vue official documentation to further understand the process of component life cycle execution:https://cn.vuejs.org/ v2/guide/instance.html#Life cycle diagram
2. Data sharing between components
2.1 Relationship between components
In project development, the most common relationships between components are divided into the following two types:Father-son relationship
Brother relationship
2.2 Data sharing between parent and child components
Data sharing between parent and child components is divided into:Parent → Child Shared data
Child → ParentShared data
2.2.1 Parent component to child Components share data
To share data from a parent component to a child component, you need to usecustom attributes. The sample code is as follows:
2.2.2 Child component shares data with parent component
Uses when child component shares data with parent componentCustom events. The sample code is as follows:
2.3 Data sharing between sibling components
In vue2.x, sibling components The data sharing scheme between them isEventBus. ?Steps for using EventBus?:
- Create the
- eventBus.js
module and share a Vue instance object externally;
On the data sender, call the - bus.$emit
('event name', data to be sent) method to trigger the custom event;
On the data receiver, call - bus.$on
('Event name', event handling function) method registers a custom event;
3. ref reference
3.1 What is ref reference
1️⃣ ref is used to assist developers to obtain DOM withoutnot relying on jQuery. A reference to an element or component. 2️⃣ Each vue component instance contains a
$refs object, which stores references to the corresponding DOM elements or components. By default, component's $refs point to an empty object . The code demonstration is as follows:
3.2 Use ref to reference the DOM elementIf you want to use If ref refers to a DOM element on the page, it can be operated as follows:
The code is demonstrated as follows:
##3.3 Use ref to reference component instances
If you want to use ref To reference the component instance on the page, you can operate as follows:
3.4 Control the on-demand switching of text boxes and buttons
Use Boolean valueinputVisible to control the on-demand switching of the text box and button in the component. The sample code is as follows:
3.5 Let the text box automatically gain focus
After the text box is displayed, if you want If it gets focus immediately, you can add a ref reference to it and call the.focus() method of the native DOM object. The sample code is as follows:
##3.6 this.$nextTick(cb) method
$nextTick of the component The (cb) method will defer the cb callback to execution
after the next DOM update cycle. The popular understanding is: wait for the DOM update of the component to be completed before executing the cb callback function. This ensures that the cb callback function can operate on the latest DOM elements. (Learning video sharing:
The above is the detailed content of A brief analysis of life cycle and data sharing in Vue. For more information, please follow other related articles on the PHP Chinese website!

vue中props可以传递函数;vue中可以将字符串、数组、数字和对象作为props传递,props主要用于组件的传值,目的为了接收外面传过来的数据,语法为“export default {methods: {myFunction() {// ...}}};”。

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!

react与vue的虚拟dom没有区别;react和vue的虚拟dom都是用js对象来模拟真实DOM,用虚拟DOM的diff来最小化更新真实DOM,可以减小不必要的性能损耗,按颗粒度分为不同的类型比较同层级dom节点,进行增、删、移的操作。


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

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
