前端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>
  
相关推荐
CodeSheep8 分钟前
大家有没有发现一个奇特现象:你能在一个公司工作 12 年以上,无论你多忠诚多卖力,一旦公司赚的少了,那你就成了“眼中钉肉中刺”
前端·后端·程序员
亿元程序员13 分钟前
你知道三国志战略版的地图是怎么实现的吗?
前端
Rewloc21 分钟前
IntelliJ IDEA 打包 Web 项目 WAR 包(含 Tomcat 部署+常见问题解决)
前端·tomcat·intellij-idea
devii6623 分钟前
120html
前端
.生产的驴24 分钟前
React useEffect组件渲染执行操作 组件生命周期 监视器 副作用
前端·css·react.js·ajax·前端框架·jquery·html5
峥无30 分钟前
HTML 零基础入门到实战:从骨架到页面的完整指南
前端·html
南囝coding37 分钟前
《独立开发者精选工具》
前端·后端·开源
IT_陈寒41 分钟前
JavaScript 性能优化的 7 个致命陷阱:我从 P5 到 P8 的核心突破都在这里!
前端·人工智能·后端
艾小码1 小时前
告别加班!这些数组操作技巧让前端开发效率翻倍
前端·javascript
Rhys..2 小时前
ES6是什么
前端·javascript·es6