前端list.push,封装多个对象

js

javascript 复制代码
   var fruit = ['apple', 'banana'];
	fruit.push('pear');
  console.log(fruit); // ['apple', 'banana', 'pear']

现在为对象

复制代码
        data1:
        {
            addUser: '1',
            editUser: '1',
            addTime: null,
            editTime: 1527410579000,
            userId: 3,
            systemNo: 'mc',
            userName: 'zengzhuo',
            userPassword: 'e10adc3949ba59abbe56e057f20f883e',
            userRealName: '系统管理员',
            userSex: 'M',
            userMobile: '18616988966',
            userEmail: '222@qq.com',
            isLock: 'N',
            deptId: 2,
            deptName: 'xxxx',
            roleId: 101
          },
        data2: 
          {
            addUser: '1',
            editUser: '1',
            addTime: null,
            editTime: 1527411068000,
            userId: 1,
            systemNo: 'pmd',
            userName: 'root',
            userPassword: 'e10adc3949ba59abbe56e057f20f883e',
            userRealName: '超级管理员',
            userSex: '女',
            userMobile: '138123456789',
            userEmail: '111@qq.com',
            isLock: 'N',
            deptId: 1,
            deptName: 'xxxx',
            roleId: 1
          },
js 复制代码
  var data0 = []
  data0.push(this.data1,this.data2)
console.log(data0)

整体代码

vue 复制代码
<template>
    <div id="app">
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
    </div>
</template>
  
<script>
export default {
    name: "App",
    data() {
    return {
        data1:
        {
            addUser: '1',
            editUser: '1',
            addTime: null,
            editTime: 1527410579000,
            userId: 3,
            systemNo: 'mc',
            userName: 'zengzhuo',
            userPassword: 'e10adc3949ba59abbe56e057f20f883e',
            userRealName: '系统管理员',
            userSex: 'M',
            userMobile: '18616988966',
            userEmail: '222@qq.com',
            isLock: 'N',
            deptId: 2,
            deptName: 'xxxx',
            roleId: 101
          },
        data2: 
          {
            addUser: '1',
            editUser: '1',
            addTime: null,
            editTime: 1527411068000,
            userId: 1,
            systemNo: 'pmd',
            userName: 'root',
            userPassword: 'e10adc3949ba59abbe56e057f20f883e',
            userRealName: '超级管理员',
            userSex: '女',
            userMobile: '138123456789',
            userEmail: '111@qq.com',
            isLock: 'N',
            deptId: 1,
            deptName: 'xxxx',
            roleId: 1
          },
          data3:[]
    }},
    methods: {
        //test事件
        search() {
            var fruit = ['apple', 'banana'];
            fruit.push('pear');
            console.log(fruit); // ['apple', 'banana', 'pear']

            fruit.push('orange', 'grape',this.data2);
            console.log(fruit); // ['apple', 'banana', 'pear', 'orange', 'grape']

           
       var data0 = []
       data0.push(this.data1,this.data2)
          
          console.log(data0)
        }
    }
};

</script>
  
<style> html,
 body {
     width: 100%;
     height: 100%;
     box-sizing: border-box;
     padding: 0px;
     margin: 0px;
 }

 #app {
     font-family: "Avenir", Helvetica, Arial, sans-serif;
     -webkit-font-smoothing: antialiased;
     -moz-osx-font-smoothing: grayscale;
     color: #2c3e50;
     widows: 100%;
     height: 100%;
 }
</style>
  
相关推荐
微祎_1 分钟前
写给新手的 triton-inference-server-ge-backend:昇腾Triton推理服务后端到底是啥?
前端·人工智能·cann
烂不烂问厨房4 分钟前
两张图片拼接在一起中间有条白线
前端
掘金安东尼7 分钟前
浏览器跨域窗口通信技术调研:window.open 与 postMessage
前端
Highcharts.js2 小时前
缺失数据可视化图表开发实战|Highcharts创建人员出生统计面积图表示例
开发语言·前端·javascript·信息可视化·highcharts·图表开发
LaughingZhu9 小时前
Product Hunt 每日热榜 | 2026-05-21
前端·人工智能·经验分享·chatgpt·html
怕浪猫9 小时前
Electron 开发实战(一):从零入门核心基础与环境搭建
前端·electron·ai编程
小鹏linux10 小时前
Ubuntu 22.04 部署开源免费具有精美现代web页面的Casdoor账号管理系统
linux·前端·ubuntu·开源·堡垒机
前端若水11 小时前
会话管理:创建、切换、删除对话历史
前端·人工智能·python·react.js
Bigger11 小时前
mini-cc:一个轻量级 AI 编程助手的诞生
前端·ai编程·claude
涵涵(互关)11 小时前
Naive-ui树型选择器只显示根节点
前端·ui·vue