当前位置:网站首页>Component value transfer: child components transfer data to parent components
Component value transfer: child components transfer data to parent components
2022-06-21 23:55:00 【Nancy-sn】
Subcomponent pass $emit Method to trigger an event
1. The subcomponent defines a method , Click to send send
2.send When triggered , Will trigger parentsend, Carrying data
3. Custom events , Method of binding parent component handler()
4. Call the method of the parent component
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<body>
<div id="app">
<p>{
{parent_msg}}</p>
<child @parentsend="handler"></child>
</div>
</body>
</html>
<script src="./js/vue.js"></script>
<script>
// Global components ( Child components )
Vue.component("child",{
template:`
<div>
<button @click=send> Send to parent </button>
</div>
`,
data(){
return{
child_msg:" Data of subcomponents "
}
},
methods:{
send(){
// Triggered parentsend, stay parentsend carry child_msg
this.$emit("parentsend",this.child_msg)
}
},
})
// Parent component
new Vue({
el:"#app",
data:{
parent_msg:""// Parent component data
},
methods:{
handler(msg){
this.parent_msg=msg;
}
}
})
</script>After operation :

After clicking the button :
边栏推荐
- 同花顺VIP开户怎么开户,安全吗?
- 211 college Master of divinity thesis swipe the screen! 75 lines wrong 20 lines! School response: the tutor stopped recruiting
- QT scrollarea qscrollarea
- Qt实用技巧:QtCreator编辑区关闭右侧不必要的警告提示
- 小程序与工业互联网是怎样相辅相成的
- 所谓的0拷贝不就是为了让CPU休息吗?深入理解mmap
- [technical remarks] [reprint]analysis of several parameters of ffmpeg compressed video
- Win11热点连接成功但没网?Win11移动热点和网络冲突的解决方法
- Uni app advanced style framework / production environment [Day10]
- Install the domestic image of scoop in Windows
猜你喜欢

Leetcode-543- diameter of binary tree

Qt实用技巧:QtCreator编辑区关闭右侧不必要的警告提示

Enterprise comprehensive networking Training II

Hardware development notes (IV): basic process of hardware development, making a USB to RS232 module (III): design schematic diagram

布局路线图,空间布局与数据可视化的完美结合

关于 allegro的pcbEditor在使用过程中经常卡或者busy无响应 的解决方法

Sigir2022 𞓜 user preference modeling in conversational recommendation system

洞见数据价值,启迪数字未来,《数字化的力量》问世

SIGIR2022 | 對話式推薦系統中的用戶偏好建模

Must the database primary key be self incremented? What scenarios do not suggest self augmentation?
随机推荐
Shanghai Jiaotong University: Kerong Wang | bootstrap transformer based on off-line reinforcement learning
被八股文害惨了。。。。
Pltmodify abscissa and ordinate colors
Hardware development notes (III): basic process of hardware development, making a USB to RS232 module (II): design principle diagram Library
What if the program input point cannot be located in the dynamic link library
About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally
张军院士:《无人智群及其社会融合》最新论文,中国工程院院刊
Enterprise comprehensive networking Training II
Prediction of enzyme activity parameters by deep learning construction of enzyme binding model
树莓派开发笔记(十六):树莓派4B+安装mariadb数据库(mysql开源分支)并测试基本操作
211 college Master of divinity thesis swipe the screen! 75 lines wrong 20 lines! School response: the tutor stopped recruiting
RK3568开发笔记(三):RK3568虚拟机基础环境搭建之更新源、安装网络工具、串口调试、网络连接、文件传输、安装vscode和samba共享服务
Enterprise wechat built-in application H5 development record-1
Voir la valeur des données, éclairer l'avenir numérique, le pouvoir numérique est sorti
标志位生成
二叉排序树
青春无言│用技术定格毕业季最美好的回忆
树莓派开发笔记(十七):树莓派4B+上Qt多用户连接操作Mysql数据库同步(单条数据悲观锁)
Solution to garbled Chinese display of securefx transmission remote server
组件传值:兄弟间传值(非父子组件进行传值)