当前位置:网站首页>setup中的props和context
setup中的props和context
2022-07-23 00:47:00 【只想挣钱,呜呜】
props的使用:用于父子组件向子级组件传送数据
(1)在子级标签中写入要传送的数据
<child :msg="msg" mdf="123"></child>
(2)子级组件接收
props:['msg','mdf'],
(3)使用,直接使用即可
<h3>msg:{
{
msg}} {
{
mdf}}</h3>
如下图所示:
context的使用
context参数,是一个对象,里面有
(1) attrs对象:获取当前组件标签上的所有属性,与props的区别:
props在使用的时候,有个注册的过程,但是如果有的数据没有注册,依然可以通过context.attrs访问到
例如:
父组件:
<child :msg="msg" mdf="123"></child>
子组件:我只接受了一个msg,mdf没有接收
props:['msg'],
我怎么拿到mdf这个东西呢?这个时候可以通过context.attrs
setup(props,context) {
console.log(context.attrs.mdf)
}
输出如下:
(2)emit方法:
emit是用来分发事件的,分发事件的目的是通过在子组件元素上绑定事件,来触发父组件中的事件,来改变父组件的数据。
用法:
父组件:真正的改变数据的方法
//@xxx="xxx"---通过emit
<child :msg="msg" mdf="123" @xxx="xxx"></child>
const xxx = (txt:string) => {
msg.value += txt
}
return {
msg,
xxx
}
子组件
<button @click="emitxxx">分发事件</button>
const emitxxx = () => {
//xxx----父组件中的方法
//'2123'---要给父组件传递的参数
context.emit('xxx','2123')
}
return {
emitxxx,
}
具体流程:
边栏推荐
- 【管理篇 / 升级】* 02. 查看升级路径 * FortiGate 防火墙
- Arduino框架下合宙ESP32C3 +1.8“TFT液晶屏通过TFT_eSPI库驱动显示
- . net to develop cloud native applications, you only need to add oil to yourself
- 解读机器人视觉类别及应用原理
- JMeter --- JMeter installation tutorial
- SIP账号的作用-告诉你什么是SIP线路
- DOM系列之禁止选中文字和禁止右键菜单
- Trigger event when input is completed
- 博途PLC信号处理系列之限幅消抖滤波
- K3s - lightweight kubernetes cluster
猜你喜欢

College students downloaded 2578 documents abnormally, and the IP of the University of Social Sciences of China was banned by a database

Pagoda installation hyperf

SIP账号的作用-告诉你什么是SIP线路

Template school jumpserver security operation and maintenance audit screen

Arduino框架下合宙ESP32C3 +1.8“TFT液晶屏通过TFT_eSPI库驱动显示

正则表达式转换为相应的文字小工具

UGUI源码解析——MaskUtilities

【管理篇 / 升级】* 02. 查看升级路径 * FortiGate 防火墙

.NET开发云原生应用,你只差给自己加个油

带你走进MySQL MVCC的世界
随机推荐
解读随着教育改革的深入steam教育
视频点播中相关分辨率说明
疫情隔离区订餐系统的开发
Is it safe to open an account online? How about Galaxy Securities
博途PLC信号处理系列之限幅消抖滤波
User defined type details: structure, enumeration, union
K3s - lightweight kubernetes cluster
Day3 POC and exp learning Pikachu brute force cracking with token
华为应用已经调用了checkAppUpdate接口,为什么应用内不提示版本更新
UGUI源码解析——IMaterialModifier
50道经典计算机网络面试题,你答得上几个?(三)
Swin-Transformer-Object-Detection项目安装教程
基于共轭梯度法的对抗攻击
BGP federal experiment
The concept and method of white box test
There was an accident caused by MySQL misoperation, and "high availability" couldn't stand it
在通达信开户安全不
正则表达式转换为相应的文字小工具
7. Image data processing of paddlepaddle
K3S - 轻量级Kubernetes集群