posts - 66,  comments - 2,  views - 55741
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1、---- 数组合并 ----

说明:定义两个数组arr1 和arr2,然后把这两个合并放入arr3中;

  const arr1=[1,2,3,4,5]
       const arr2=[6,7,8,9]
   //合并数组
      const arr3=[...arr1,...arr2]
  //转字符串以逗号分割
      const arr4=arr3.join(',')
      console.log(">>>>>>====",arr4);
      console.log(typeof arr4);
结果:

 

 

2、-----数据替换(更新)----

  1. // 以this.info的内容为模板 根据...dataObj里面改变的内容去替换this.info的内容
  2.  this.info={...this.info,...dataObj}
<template>
<div>
        <el-button type="primary" @click="click">点击</el-button>
        <div>打印信息{{ info }}</div>
    </div>
</template>

<script>
export default {
  data(){
    return{
      info:{
        name:'张三',
        age:10
      }
    }
  },
  methods:{
    // 获取主界面信息
    click(){
      // 创建新对象,两种方式
      // 方式一:直接声明式
      // const newInfo={name:'李四',age:20}
        this.info = {...this.info,...newInfo}
 
      // 方式二:使用Object构造函数创建对象
      const obj = new Object({name:'王五',age:30,addr:'南京'})

      this.info = {...this.info,...obj}//新对象obj数据给this.info
    }
  }
 
>

 

 【结果>>>】

 

 

 

posted on   给天使看的戲  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示