vue prop属性传值与传引用示例
作者:幻欢子 时间:2024-05-10 14:10:16
vue组件在prop里根据type决定传值还是传引用。
简要如下:
传值:String、Number、Boolean
传引用:Array、Object
若想将数组或对象类型也以值形式传递怎么办呢?如下方式可以实现:
// component-A 引用component-B组件
<component-B :person="personList"
:personBak="person_Bak">
</component-B>
// component-A 部分关键代码
// 将数组复制,personBak与personList是两个“内容”相同但地址不一样的对象(数组),
// 这样可以变相的实现“传值”,person或personBak互不影响
person_Bak = JSON.parse(JSON.stringfy(this.personList));
//component-B props部分
props: {
person: {
type: Object,
default: {}
},
personBak: {
type: Object,
default: {}
}
}
来源:https://blog.csdn.net/u012424148/article/details/82587197
标签:vue,prop,传值,传引用
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
用python写爬虫简单吗
2024-01-02 08:03:26
Python Flask微信小程序登录流程及登录api实现代码
2022-03-21 14:33:47
![](https://img.aspxhome.com/file/2023/4/133254_0s.gif)
浅谈Python2之汉字编码为unicode的问题(即类似\\xc3\\xa4)
2021-12-14 07:07:19
js仿腾讯QQ的web登陆界面
2024-04-18 09:41:14
![](https://img.aspxhome.com/file/2023/5/136295_0s.jpg)
用js判断页面刷新或关闭的方法(onbeforeunload与onunload事件)
2024-04-30 08:55:07
oracle数据库创建备份与恢复脚本整理
2023-07-13 00:57:20
如何用Python将图片转为字符画
2022-06-15 09:26:06
![](https://img.aspxhome.com/file/2023/3/130963_0s.png)
golang 微服务之gRPC与Protobuf的使用
2023-06-17 20:36:03
通过Python爬虫代理IP快速增加博客阅读量
2023-08-17 16:17:55
深入解析JavaScript中的arguments对象
2024-05-09 14:50:44
Python海龟绘图详解
2022-07-26 02:02:02
![](https://img.aspxhome.com/file/2023/7/133427_0s.png)
基于python的BP神经网络及异或实现过程解析
2021-10-29 00:02:01
![](https://img.aspxhome.com/file/2023/8/72778_0s.jpg)
mysql8.0.21下载安装详细教程
2024-01-26 15:40:00
![](https://img.aspxhome.com/file/2023/2/69242_0s.jpg)
Python内建类型float源码学习
2022-05-05 17:07:37
![](https://img.aspxhome.com/file/2023/2/90642_0s.png)
基于python实现把json数据转换成Excel表格
2021-02-20 05:22:04
uploadify在Firefox下丢失session问题的解决方法
2024-02-27 01:33:31
数据库 关键字一览表
2024-01-22 23:27:21
深入探讨opencv图像矫正算法实战
2022-06-03 16:20:39
![](https://img.aspxhome.com/file/2023/8/102858_0s.jpg)
python爬虫如何解决图片验证码
2021-04-27 11:58:57
Python超简单分析评论提取关键词制作精美词云流程
2021-07-27 22:00:41
![](https://img.aspxhome.com/file/2023/3/67833_0s.png)