What is the vue component? Components are reusable Vue instances. It is essentially an object that contains member attributes such as data, computed, watch, methods, filters, and vue component life cycle hooks. This article will give you a detailed introduction to the content of the vue component.
Let’s take a look at the component structure first:
{ data(){ return { // } }, computed:{ displayName(){ return ''; } }, methods:{ onClickHandler(params){ // do something } } }
Basic knowledge:
data attribute
The data attribute maintains the internal state of a component, and other components are not visible under normal circumstances.
Currently I don’t know how to monitor its changes;
Because the calculated attribute computed and the listening attribute watch can only monitor changes in responsive dependencies, and $refs is not responsive.
Can be passed to child components through props;
Can be passed to parent components through $emit;
Can be passed to this.$refs.ref.$data in mounted Get the internal state of the child component during the life cycle;
The data option of a component must be a function.
data选项有两种定义方式: 一、对象形式: ``` data:{ //引用该组件的地方,共用一个状态的引用,以至于,只要有一处修改了$data中的某一属性值,其它引用该组件的地方也跟随着改变该属性值(其实,不是跟随,本来就是同一个指向)。 } ``` 二、函数形式: ``` data(){ return { //引用该组件的地方,每一个组件都会获得独立的引用,互不干扰。 } } ```
computed attribute, methods attribute, filter
method | computed | filter | |
---|---|---|---|
Function | Data variable | Function | |
Used as event processing function | Used as data | Used as pipe symbol | |
Intra-organization | Intra-organization | Intra-organization (local registration), global (global registration) | |
Can take parameters | Without parameters (non-function) | With parameters | |
No Requirements | must have | must have | |
triggered when interacting | in its related dependencies It will be re-evaluated only when changes occur | Executed when the incoming data changes |
Note:
Not all properties in Vue are responsive, for example, $refs cannot monitor its changes; The main difference in component construction is thetemplate generation method.
Template definition method
template option
String template
A string composed of HTML tag structure; Example:{ template: '<h1 id="简单示例">简单示例</h1>', props: { level: { type: Number, required: true } } }The template specified by the id selector Wrapped with a script tag identified by id HTML fragment; Example:
<script> <h1 v-if="level === 1"> 简单示例 </script> { template: '#anchored-heading-template', props: { level: { type: Number, required: true } } }
render
Use the maximum programming capabilities of JavaScript. This function receives a createElement method as the first parameter Used to create VNode; createElement receives three parameters: component root node type, component configuration object, child node (official description of component configuration object); Example:{ render: function (createElement) { return createElement( 'h' + this.level, // tag name 标签名称 this.$slots.default // 子组件中的阵列 ) }, props: { level: { type: Number, required: true } } }
vue single file component
Single file component structurally separates templates, logic, and styles and saves them in the same file.<template> <div> ... </div> </template> <script> ... export default{ ... } ... </script> <style> ... </style>
Plan selection
Single file | render | |
---|---|---|
Conventional choices | Choices when the previous two solutions cannot solve the problem (high flexibility) |
The above is the detailed content of What are vue components? Introduction to Vue components. For more information, please follow other related articles on the PHP Chinese website!

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
