vue遍历Map,Map在vue中的使用方法

Map在vue中的使用方法:

html:遍历的时候要遍历两遍


js:

  data(){
            return{
             	cur: "0",
                active:"0",
                courseTypeList: [],
                dateMap:{},
            }
        },
 mounted(){
  		// 后端返回json
          var jsonStr ={
			    "code": 0,
			    "msg": "success",
			    "data": {
			        "courseTypeList": [
			            {
			                "id": "16",
			                "courseTypeName": "小一班"
			            },
			            {
			                "id": "15",
			                "courseTypeName": "中一班"
			            },
			            {
			                "id": "14",
			                "courseTypeName": "大一班"
			            }
			        ],
			        "dateKeys": [
			            "二·11.26",
			            "三·11.27",
			            "四·11.28",
			            "五·11.29",
			            "六·11.30",
			            "日·12.01",
			            "一·12.02"
			        ]
			    }
			}
            // 遍历班级类型
            for (var i = 0; i < jsonStr.data.courseTypeList.length; i++) {
                var courseTypeList = jsonStr.data.courseTypeList[i];
                this.courseTypeList.push(courseTypeList)
            }

            // 遍历日期
            //初始化Map对象
            var dateMap = new Map();
            for (var i = 0; i < jsonStr.data.dateKeys.length; i++) {
                var data = jsonStr.data.dateKeys[i];
                	//用split连在一起的字符串切割 "三·11.27"
                   //使用set添加键值示例:m.set('小红', 30);
                dateMap.set(data.split("·")[0], data.split("·")[1]);
            }
            this.dateMap = dateMap;
        },

css:

  .ctNavbar{
        display: flex;
        align-items: center;
        justify-content: space-between;
        text-align: center;
        .ctA{
            padding: 10px 0;
            color: #202020;
            font-size: 1.5rem !important;
            border-bottom: 2px solid transparent;
            width: 33%;
            &.cur{
                color: #BA0932;
                border-bottom: 2px solid #BA0932;
            }
        }
    }
       .date_navbar {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        a {
            width: 32px;
            -webkit-box-flex: 1;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-direction: column;
            font-size: 9px;
            color: #6C6C6C;
            padding: 2px 5px;
            flex: 1;
            span {
                display: block;
                -webkit-box-flex: 1;
            }
            &.cur {
                background: #BA0932;
                color: #fff;
                border-radius: 16px;
            }
        }
    }

你可能感兴趣的:(java,java,后端)