1.在父组件中使用子组件的地方绑定数据
<children :message="message"></children>
2.子组件使用props接收父组件传过来的数据
props:{ message:String }
3.示例:
1.子组件直接使用$emit将内部数据传递给父组件
this.$emit("childByValue",this.childValue);
2.父组件中接收数据
<template> <child @childByVlaue="childByVlaue"></dhild> </template> methods:{ childByValue:function(childValue){ this.name=childValue; } }
(三)可以通过
p
a
r
e
n
t
和
parent和
parent和children获取父子组件参数
$children[i].params this.$parent.params
1.在state里定义数据和属性
state: { userName: '', },
2.在mutation里定义函数
mutations: { setUserName(state, name) { state.userName = name }, },
3.设置值
this.$store.comit('setUserName',params)
4.获取值
this.$store.state.user.userName
1.子组件的方法
methods:{ childMethod(){ alert("我是子组件的方法"); } }
2.父组件调用子组件的方法
<template> <child ref="child"></child> <div @click="parentMethod"></div> </template> methods:{ parentMethod(){ this.$refs.child.childMethod(); } }
热门文章
- 「2月1日」最高速度21.8M/S,2025年Shadowrocket/SSR/Clash/V2ray每天更新免费节点订阅链接
- 动物疫苗去哪里买的好呢(动物注射疫苗注射哪里)
- Java开发日志EasyExcel自定义类型转换、Excel表头字段问题
- 「1月27日」最高速度20.9M/S,2025年Clash/SSR/V2ray/Shadowrocket每天更新免费节点订阅链接
- 品牌狗粮性价比高(狗粮性价比高的)
- 宠物医院治仓鼠贵不贵呀(宠物医院仓鼠收费价目表)
- 宠物粮市场分析论文题目(宠物粮调研)
- 动物疫苗空瓶无害化处理措施有哪些(动物疫苗如何存放)
- 小动物要打什么疫苗(小动物打疫苗多少钱)
- 「1月25日」最高速度18.5M/S,2025年SSR/Shadowrocket/V2ray/Clash每天更新免费节点订阅链接