


Vue2.0 parent and child components transfer functions to each other (with code)
This time I will bring you the mutual transfer function of Vue2.0 parent and child components (with code). What are the precautions for the mutual transfer function of Vue2.0 parent and child components. The following is a practical case, let's take a look. one time.
What is Vue.js
Vue.js (pronounced /vjuː/, similar to view) is a progressive framework for building user interfaces. Unlike other heavyweight frameworks, Vue Designed with bottom-up incremental development. Vue's core library only focuses on the view layer, which is not only easy to get started, but also easy to integrate with third-party libraries or existing projects. On the other hand, when working with single file components and Vue When combined with ecosystem-supported libraries, Vue is also fully capable of providing drivers for complex single-page applications. Study notes: In vue2.0, when a parent component calls a child component, it wants to pass the function body in the parent component as well.
1. Through props: applicable when parameters need to be passed from child components to parent components
// Parent component.vue<template>
<p>
<ok-input :params='number' :callback='callbackNum'></ok-input>
</p>
</template>
<script type="text/ecmascript-6">
import okInput from '../ok-input/okinput.vue';
export default {
props: {},
data() {
return {
number: {},
callbackNum: function (x) {
console.log(x);
}
};
},
methods: {
},
components: {
'ok-input': okInput
}
};
</script>
<template>
<p>
<input v-model='numVal' @change='handleFun'></input>
</p>
</template>
<script type="text/ecmascript-6">
import {Input, Select, Option, Button} from 'element-ui';
import 'element-ui/lib/theme-default/index.css';
export default {
props: {
params: {
type: Object,
default: {
type: ''
}
},
callback: {}
},
data() {
return {
x: 'hah',
numVal: ''
};
},
methods: {
handleFun(val) {
this.callback(val); // 将参数传回父组件中的回调函数
}
},
components: {
'el-input': Input,
}
};
</script>
2. Via $emit: Applicable only when obtaining the current operation object // 父组件.vue
<template>
<p>
<ok-input :params='inputs' @change='handleAge'></ok-input>
</p>
</template>
<script type="text/ecmascript-6">
import okInput from '../ok-input/okinput.vue';
export default {
props: {},
data() {
return {
number: {}
};
},
methods: {
handleAge(evt) {
console.log(evt.target.value); // 接收从子组件传过来的当前对象
}
},
components: {
'ok-input': okInput
}
};
</script>
<template>
<p>
<input v-model='numVal' @blur='handleChange'></input>
</p>
</template>
<script type="text/ecmascript-6">
import {Input, Select, Option, Button} from 'element-ui';
import 'element-ui/lib/theme-default/index.css';
export default {
props: {
params: {
type: Object,
default: {
type: ''
}
},
callback: {}
},
data() {
return {
x: 'hah',
numVal: ''
};
},
methods: {
handleChange(evt) {
this.$emit('change', evt); // 将当前对象 evt 传递到父组件
},
},
components: {
'el-input': Input,
}
};
</script>
Recommended reading:
The above is the detailed content of Vue2.0 parent and child components transfer functions to each other (with code). 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



Delivery Optimization is a feature that helps Windows Update and Windows Store run and deliver updates faster. Cache files in Delivery Optimization are supposed to be deleted after a while, but for some of our readers they keep piling up and taking up unnecessary space. Is it safe to delete delivery optimization files? Yes, it is safe to delete delivery optimization files, and in this article, you will find out how easy it is to do so in Windows 11. Although it is not recommended to manually delete delivery optimization files, it is possible to do so automatically. How to delete delivery optimization files on Windows 11? Click the search bar, type Disk Cleanup, and open the tool from the results. If you have multiple drives, select the drive with your system (usually C:

The context package in the Go language is used to pass request context information in the program. It can pass parameters, intercept requests and cancel operations between functions across multiple Goroutines. To use the context package in Go, we first need to import the "context" package. Below is an example that demonstrates how to use the context package to implement request parameter passing. packagemainimport("context"

How to solve Vue error: Unable to use props to pass data Preface: During the development process of Vue, it is very common to use props to transfer data between parent and child components. However, sometimes we may encounter a problem, that is, when using props to pass data, an error will occur. This article will focus on how to solve the error that props cannot be used to pass data in Vue. Problem description: In Vue development, when we use props in the parent component to pass data to the child component, if

Introduction Message passing is a method of transmitting communication between items or threads and is a fundamental idea in distributed systems and parallel programming. Depending on the specific needs of the implementation, message transfer in Java can be accomplished through various methods and structures using the power source java.util.concurrent container, which provides a series of interfaces and class libraries for establishing and handling threads as active locks And the synchronization mechanism is a single method in Java that implements message delivery, such as instances. For example, the Executor interface can be used immediately to execute tasks, while BlockingQueue connections can be used to pass statements between concurrent processes. The above is a flow chart of the entire process of message passing in Java. Interface typeExecu

In PHP, you can use the ampersand (&) symbol to pass variables by reference instead of by value. This allows the original variable to be modified within a function or method. There are mainly two ways to pass PHP variables by reference: Using ampersand symbol Using ampersand symbol in function/method declaration Using ampersand symbol in function/method declaration When passing variables to function/method In PHP, you can use function/ The ampersand symbol (&) in a method declaration passes variables by reference. Here is the updated explanation: To pass a reference variable by using the & symbol in a function/method declaration, you need to include the & symbol before the parameter name in the function/method definition. This indicates that parameters should be passed by reference, allowing

Go is a strongly typed programming language, and its function parameters are passed by value. This means that when you pass a parameter to a function, you are actually making a copy of the parameter's value and passing that value to the function for processing. Therefore, when using function parameter passing in Go, you need to pay attention to the following points: The difference between value types and reference types In Go, except for the basic data type which is a value type, all data types are reference types. When value type data is passed as a function parameter, a copy of the value will be copied and passed to the function; while reference type data

As a language widely used in website backend development, PHP's function parameter passing is also one of its basic features and is very important. This article will explain in detail the relevant knowledge of PHP function parameter passing. Pass-by-value and pass-by-reference There are two ways to pass PHP function parameters: pass-by-value and pass-by-reference. Passing by value means copying the value of the actual parameter to the formal parameter. Modifications to the formal parameter within the function will not affect the actual parameter. Passing by reference passes the memory address of the actual parameter to the formal parameter. Modifications to the formal parameter within the function will also directly affect the actual parameter. For example: function

How to deal with distributed transactions and message passing problems and solutions in C# development. In distributed systems, distributed transactions and message passing are common problems. Distributed transactions refer to transactions involving multiple databases or services, while messaging refers to asynchronous communication between different components in the system. This article will introduce how to deal with these issues in C# development and provide specific code examples. 1. Distributed transaction problems and solutions In traditional single-node transactions, the transaction processing logic is encapsulated in a database operation. However, in distributed
