What is vue component
In vue, a component is a reusable Vue instance. It has a unique component name. It can extend HTML elements and use the component name as a custom HTML tag. Components can greatly improve code reuse.
The operating environment of this tutorial: Windows 7 system, vue version 2.9.6, DELL G3 computer.
What are components?
Component is an important concept in Vue. It is a reusable Vue instance. It has a unique component name. It can extend HTML elements and use the component name as customized HTML. Label. Because components are reusable Vue instances, they receive the same options as new Vue(), such as data, computed, watch, methods, and life cycle hooks. The only exceptions are root-instance-specific options like el.
Extract some common modules and write them into separate tool components or pages, which can be directly introduced into the required pages. Then we can extract it as a component for reuse.
For example, if multiple pages use the same components, they can be made into components, which improves the code reuse rate.
Using Vue components
Let’s talk about our directory first
1. Create our component B.vue
##Similarly, Create a new hello_word.vue as the parent
hello_word.vue // import showB from './B.vue' Introduce components
Registered component
components:{ showB, }, <showB /> //使用组件
Note: Define component names in camel case, such as: Use PascalCase Use kebab-case
Start getting to the main topic props
The parent component passes the value to the child component(The parent component binds data such as: value="It's time to work ", the child component obtains it through props) The props option of the child component can receive data from the parent component. That's right, it can only be received. Props are one-way bound, that is, they can only be passed from the parent component to the child component, not the other way around.
Usage is as follows:
##. The result is
The child component passes the value to the parent componentIn the child component:
<p @click="chuanzhi">回复父组件</p> chuanzhi() { this.$emit('msg', '知道了知道了') //执行 msg 函数并把要改变的值作为参数带过去 }
Parent component:
Introduce @msg='msg' in DOM
<showB :value='text' @msg='msg'/> msg(val){ console.log(val,'val') }
Receive through the method
Run, click to reply to the parent component
Print results:
For more programming-related knowledge, please visit: Programming Learning! !
The above is the detailed content of What is vue component. 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



Vue component communication: Use $destroy for component destruction communication In Vue development, component communication is a very important aspect. Vue provides a variety of ways to implement component communication, such as props, emit, vuex, etc. This article will introduce another method of component communication: using $destroy for component destruction communication. In Vue, each component has a life cycle, which includes a series of life cycle hook functions. The destruction of components is also one of them. Vue provides a $de

With the continuous development of front-end technology, Vue has become one of the popular frameworks in front-end development. In Vue, components are one of the core concepts, which can break down pages into smaller, more manageable parts, thereby improving development efficiency and code reusability. This article will focus on how Vue implements component reuse and extension. 1. Vue component reuse mixins Mixins are a way to share component options in Vue. Mixins allow component options from multiple components to be combined into a single object for maximum

Vue Practical Combat: Date Picker Component Development Introduction: The date picker is a component often used in daily development. It can easily select dates and provides various configuration options. This article will introduce how to use the Vue framework to develop a simple date picker component and provide specific code examples. 1. Requirements analysis Before starting development, we need to conduct a requirements analysis to clarify the functions and characteristics of the components. According to the common date picker component functions, we need to implement the following function points: Basic functions: able to select dates, and

Vue component communication: using watch and computed for data monitoring Vue.js is a popular JavaScript framework, and its core idea is componentization. In a Vue application, data needs to be transferred and communicated between different components. In this article, we will introduce how to use Vue's watch and computed to monitor and respond to data. watch In Vue, watch is an option, which can be used to monitor the changes of one or more properties.

Vue is a popular JavaScript framework that provides a wealth of tools and features to help us build modern web applications. Although Vue itself already provides many practical functions, sometimes we may need to use third-party libraries to extend Vue's capabilities. This article will introduce how to use third-party libraries in Vue projects and provide specific code examples. 1. Introduce third-party libraries The first step to using third-party libraries in a Vue project is to introduce them. We can introduce it in the following ways

Vue component development: Tab component implementation method In modern web applications, the tab page (Tab) is a widely used UI component. The Tab component can display multiple related content on a single page and switch them by clicking on the tab. In this article, we will introduce how to implement a simple tab component using Vue.js and provide detailed code examples. The structure of the Vue tab component. The tab component usually consists of two parts: tab and panel. Labels are used to identify surfaces

To deeply understand Vue's component life cycle, you need specific code examples. Introduction: Vue.js is a progressive JavaScript framework that is favored by developers for its simplicity, ease of learning, efficiency and flexibility. In the component development of Vue, understanding the life cycle of components is an important part. This article will delve into the life cycle of Vue components and provide specific code examples to help readers better understand and apply them. 1. Life cycle diagram of Vue components The life cycle of Vue components can be regarded as components

How to switch between multiple data interaction methods in Vue components. When developing Vue components, you often encounter scenarios where you need to switch to different data interaction methods, such as requesting data through APIs, entering data through forms, or pushing data in real time through WebSocket, etc. . This article will introduce how to implement this switching of multiple data interaction methods in Vue components, and provide specific code examples. Method 1: API request data In some cases, we need to request data through API to obtain background data. under
