前端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>
  
相关推荐
wkj0013 小时前
vue中 js-cookie 用法
前端·javascript·vue.js
GoldKey7 小时前
gcc 源码阅读---语法树
linux·前端·windows
Xf3n1an8 小时前
html语法
前端·html
张拭心8 小时前
亚马逊 AI IDE Kiro “狙击”Cursor?实测心得
前端·ai编程
烛阴8 小时前
为什么你的Python项目总是混乱?层级包构建全解析
前端·python
@大迁世界9 小时前
React 及其生态新闻 — 2025年6月
前端·javascript·react.js·前端框架·ecmascript
红尘散仙10 小时前
Rust 终端 UI 开发新玩法:用 Ratatui Kit 轻松打造高颜值 CLI
前端·后端·rust
新酱爱学习10 小时前
前端海报生成的几种方式:从 Canvas 到 Skyline
前端·javascript·微信小程序
袁煦丞10 小时前
把纸堆变数据流!Paperless-ngx让文件管理像打游戏一样爽:cpolar内网穿透实验室第539个成功挑战
前端·程序员·远程工作
慧慧吖@10 小时前
关于两种网络攻击方式XSS和CSRF
前端·xss·csrf