current position:Home>Vue parent-child component mutual transmission and intermodulation
Vue parent-child component mutual transmission and intermodulation
2022-04-29 08:50:28【囍囍囍囍囍囍囍囍囍囍 A】
- The parent component passes the child component
The parent component passes to the child component through prps
Take a chestnut :
Parent component writing :content To transfer the contents of sub components
<UEditor :content="content" ref="mychild"></UEditor>
Subcomponent pass props receive
props: {
content: {
type: String,
default: function () {
return "";
},
},
},
- Child component to parent component
Subcomponent pass $emit Pass to parent component
Sub component writing :
methods: {
childHandleclick() {
// getHandleContent() Parent component method
this.$emit('getHandleContent',this.newContent)
}
},
Parent component passed @getHandleContent="getHandleContent" receive
Parent component writing
<UEditor :content="content" ref="mychild" @getHandleContent="getHandleContent" ></UEditor>
// Parent component method
getHandleContent(content) {
// Receive the value returned by the sub component
this.content = content;
},
- Parent component calls child component
<UEditor :content="content" ref="mychild"></UEditor>
//childHandleclick() Subcomponent methods
this.$refs.mychild.childHandleclick();
- The child component calls the parent component
//parentHandleclick() Parent component method
this.$parent.parentHandleclick();
- The parent component passes the method to the child component , Subcomponents call directly
Parent component
<template>
<div>
<child :fatherMethod="fatherMethod"></child>
</div>
</template>
<script>
import child from '~/components/dam/child';
export default {
components: {
child
},
methods: {
fatherMethod() {
console.log(' test ');
}
}
};
</script>
Child components
<template>
<div>
<button @click="childMethod()"> Click on </button>
</div>
</template>
<script>
export default {
props: {
fatherMethod: {
type: Function,
default: null
}
},
methods: {
childMethod() {
if (this.fatherMethod) {
this.fatherMethod();
}
}
}
};
</script>
copyright notice
author[囍囍囍囍囍囍囍囍囍囍 A],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204290621251317.html
The sidebar is recommended
- How to configure Vue in Vue project config. JS to solve cross domain problems
- Centos6 makes nginx-1.21.6-rpm package -- the way to build a dream
- [vue2-sgg v] vuex
- [vue2-sgg vi] route Vue router guard
- [vue2-sgg VII] Vue export and deploy to nginx --- UI component library (element UI...)
- Chapter 12 Ajax
- Clion remote debugging ubutun server, blood lessons
- The latest vue-i18n international plug-in realizes language switching (with source code)
- Vue monitors watch usage
- Vue encapsulates Axios to the full version of the calling interface (code source code)
guess what you like
Watch data monitoring in Vue and detailed explanation of various attributes in watch
Vue encapsulates Axios to call interface Full Version (code source code) latest recommendation (II)
Vue encapsulates Axios to the full version of the calling interface (code source code)
Ajax usage based on JQ
Vue project optimization
Vue - form generator form code generation
Data acquisition in vuex is assigned to the local problem, and when is vuex data assigned to the local problem
The modal box component is encapsulated in Vue, and the animation effect in Vue
Swiper, the application of swiper in Vue, and various versions of swiper are applied in Vue projects
Python——ReadTimeoutError: HTTPSConnectionPool(host=‘files.pythonhosted.org‘, port=443)
Random recommended
- Lesson 3 of ROS quick start - subscriber subscriber of ROS
- A lifeless face
- Mock in Vue JS preliminary simple use
- The Java Web servlet triggers the alert box on the front end
- CSS sets the color of the small vertical bar in front of the title
- Incomplete display of CSS background image
- [front end learning notes] save the front-end related codes
- Precautions for AWS serverless design dynamodb
- AWS serverless design - apigateway
- AWS serverless design lambda
- AWS serverless design - firewall WAF
- AWS serverless design-s3
- Python repeated element determination function program
- Nginx direction agent solves cross domain Problems-2
- The foundation of JavaScript
- DOM based on JavaScript
- Javascript based BOM
- JavaScript advanced functions
- Basic summary of JavaScript advanced
- Object oriented JavaScript
- JavaScript advanced threading mechanism and event mechanism
- HTML+CSS
- Introduction to less
- CSS3 media query
- Learn about bootstrap
- JQuery learning
- Ajax case
- Ajax sends a post request
- Ajax sends get requests
- Ajax notes
- Ajax learning notes
- Relearn react (1) - recognize the life cycle
- Small problems encountered by react usereducer and Solutions
- CSS realizes the square of adaptive screen width
- Nginx + ModSecurity setup
- Bootstrap web job
- bootstrap
- Swoft 2. X Foundation (HTTP, database, redis)
- Docker actual combat case 2: nginx load balancing
- Vue basic syntax