vue数组进行分组

数组进行分组使用switch方法

<template>
  <v-layout>
    <v-card contextual-style="dark" v-if="show">
      <span slot="header">
        一级主页面
      </span>
      <div slot="body">主内容页
        <!-- <div v-for="item in listTittle" :key="item.id">{{item}}</div>         -->
        <!-- <div v-for="item in list" :key="item.id">
            <p>{{listTittle}}{{item.name }}</p>
          </div> -->
        <div>
          <ul>
            <li>需求:{{lists.demand}}</li>
            <li>用户:{{lists.user}}</li>
            <li>时间:{{lists.time}}</li>
          </ul>
        </div>
      </div>
      <div slot="footer" :showDate="showDate">
        <div>来自主页面</div>
        <button type="button" class="btn btn-info " @click="toggle1">去子组件并传递数据</button>
      </div>

    </v-card>
    <v-card contextual-style="dark" v-else>
      <span slot="header">
        组件主页
      </span>
      <div slot="body">组件内容页</div>
      <div slot="footer">
        <div>来自组件页面</div>
        <my-button showDate="***父组件传递的数据***" @toggleEvent="toggle"></my-button>
      </div>

    </v-card>

  </v-layout>
</template>

<script>
/* ============
 * Home Index Page
 * ============
 *
 * The home index page.
 */

import VLayout from ‘@/layouts/Default‘;
import VCard from ‘@/components/Card‘;
import MyButton from ‘@/components/MyButton‘;

export default {
  /**
   * The name of the page.
   */
  name: ‘home-index‘,
  data() {
    return {
      show: true,
      showDate: "父子间传过来的数据",
      lists: {
        demand: [],
        user: [],
        time: []
      },
      list: [{ id: 1, name: ‘需求1‘, code: ‘admin.demand‘ },
      { id: 2, name: ‘需求2‘, code: ‘admin.demand‘ },
      { id: 3, name: ‘用户1‘, code: ‘admin.user‘ },
      { id: 4, name: ‘用户2‘, code: ‘admin.user‘ },
      { id: 5, name: ‘时间1‘, code: ‘admin.time‘ },
      { id: 6, name: ‘时间2‘, code: ‘admin.time‘ },
      { id: 7, name: ‘用户3‘, code: ‘admin.user‘ },]
    }
  },
  methods: {
    toggle1() {
      this.show = false;
    },
    toggle(data) {
      console.log(data)
      this.show = data;
    },
    listinfo() {

      this.list.map((x) => {
        console.log(x.code.split(".")[1])
        switch (x.code.split(".")[1]) {
          case "demand":
            this.lists.demand.push(x.name);
            // 执行代码块 1
            break;
          case "user":
            // 执行代码块 2
            this.lists.user.push(x.name);
            break;
          case "time":
            // 执行代码块 3
            this.lists.time.push(x.name);
            break;
          default:

        }
      })
    }
  },
  mounted() {
    // this.toggle();
    this.listinfo();
  },
  /**
   * The components that the page can use.
   */
  components: {
    VLayout,
    VCard,
    MyButton
  },
};
</script>
时间: 2024-08-10 15:12:07

vue数组进行分组的相关文章

关于vue数组中对象属性变更页面没重新渲染的问题

前段时间做开发的时候用mqtt监听了服务端信息,推送过来的数据要变更数组里面的对象的数据,修改好后但是页面并没有更新,因为javascript机制,vue并不能检测到数组变化,也是查阅知道了$set()函数, 具体用法: arr.$set(index, { name : value }), index: 索引,name: 数组中对象的属性名, value: 要赋给属性的值 this.footerList.$set(i, { siteId : monitorSiteData[j].siteId,

OC中动态创建可变数组的问题.有一个数组,数组中有13个元素,先将该数组进行分组,每3个元素为一组,分为若干组,最后用一个数组统一管理这些分组.(要动态创建数组).两种方法

<span style="font-size:24px;">//////第一种方法 // NSMutableArray *arr = [NSMutableArray array]; // for (int i = 0; i < 13; i ++) { // [arr addObject:[NSString stringWithFormat:@"lanou%d",i + 1]]; // } // NSLog(@"%@",arr);

vue 数组对象取对象的属性: Cannot read property &#39;xxxx&#39; of undefined

{{ list[0].name }} list[0]没有定义 能正确打印出想要的结果,但就是报错,外面套个v-for就没错了 很费解 与异步有关,解决办法: <template v-if=list[0]> {{ list[0].name }} </template> https://www.v2ex.com/amp/t/402145 vue 数组对象取对象的属性: Cannot read property 'xxxx' of undefined 原文地址:https://www.c

Vue数组双向绑定内幕

在Vue使用期间,我们经常会遇到对于数组的操作,但是Vue中如何实现数组双向绑定的呢,在这篇PPT中,首先回顾Vue双向绑定原理,之后再去研究Vue对于数组的特殊处理. ppt:Vue数组双向绑定内幕 参考:https://ustbhuangyi.github.io/vue-analysis/ 原文地址:https://www.cnblogs.com/MarphyDemon/p/11487764.html

vue 数组

今天项目中发现的一个问题: 在vue项目中输出一个数组,明明有俩个值:0,6,但是length为1 正常的是这样的 结果研究发现,是vue源码的问题,具体内容如下: 转载自:http://www.cnblogs.com/Darlietoothpaste/p/6682407.html Vue的数组操作的实现代码大致如下: 1 const aryMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']; 2

关于Vue数组操作

Vue的数组操作的实现代码大致如下: const aryMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse']; const arrayAugmentations = []; aryMethods.forEach((method)=> { // 这里是原生Array的原型方法 let original = Array.prototype[method]; // 将push, pop等封装好的方法定义在对

awk 用数组实现分组统计求和

[[email protected] ~]# cat 2_awk.txt #txt文档有三列数据 1  A  1 2  B  2 3  C  1 4  D  1 5  E  3 6  A  2 7  B  1 8  C  2 9  D  3 [[email protected] ~]# cat 2_awk.txt|awk '{print $1,$2}' #打印第一列和第二列 1 A 2 B 3 C 4 D 5 E 6 A 7 B 8 C 9 D (1)统计ABCDE出现的次数 [[email p

按照单词的字母是否相同对字符串数组进行分组

今天收到一个面试题:给了一个数组(如: ["cars", "thing", "scar", "dog", "god", "arcs", "the"]),需要把由颠倒字母顺序组成的单词放到同一个数组(生成后的结果:[["cars", "scar", "arcs"], ["thing"], [

vue数组中对象属性变化页面不渲染问题

做checkbox多选功能的时候遇到了一个坑,逻辑怎么看都对,但是就是有bug,最后发现数组那里值变了页面勾选没有重新渲染. 换了关键词搜索找到了相关方法. 其实之前读文档教程的时候看到过这里,但是只有真的使用之后才会有最直接的感触. ------------------------------------------- 数组更新检测 变异方法 Vue 包含一组观察数组的变异方法,所以它们也将会触发视图更新.这些方法如下: push() pop() shift() unshift() splic