• Vue3实现宫格转换(2x2,4x4,5x5等)


    核心思路:通过grid布局,点击切换class。

    核心代码(如有疑惑地方,下方有完整代码链接)

       //宫格转换
        const changeGrid = (item) => {
          state.posList = [];
          const { id } = item;
          //职责链模式进行存储,避免if else
          let map = new Map([
            [
              "0",
              {
                //对应每格宫格模式的样式
                class: "grid-two-two",
                //格子数量
                length: 4,
              },
            ],
            [
              "1",
              {
                class: "gird-three-three",
                length: 9,
              },
            ],
            [
              "2",
              {
                class: "gird-four-four",
                length: 16,
              },
            ],
            [
              "3",
              {
                class: "gird-five-five",
                length: 25,
              },
            ],
            [
              "4",
              {
                class: "gird-two",
                length: 2,
              },
            ],
            [
              "5",
              {
                class: "header-foot-foot",
                length: 3,
              },
            ],
            [
              "6",
              {
                class: "left-one-box",
                length: 6,
              },
            ],
            [
              "7",
              {
                class: "header-more",
                length: 9,
              },
            ],
            [
              "8",
              {
                class: "left-four",
                length: 13,
              },
            ],
          ]);
          state.gridList = initList(map.get(`${id}`).length);
          state.gridMode = map.get(`${id}`).class;
          nextTick(() => {
            initPos(domlist);
          });
        };

    实现效果:http://www.lintools.top 进入宫格切换模块

    代码:https://github.com/chongchongLin/vue3-question/blob/main/src/components/Grid.vue

    觉得对您有帮助的话,不妨给个star吧~

  • 相关阅读:
    MySQL 日志管理
    nginx 日志分割
    Canvas 动态小球重叠效果
    Canvas制作动态进度加载水球
    js 多张爆炸效果轮播图
    js 多张图片加载 环形进度条
    INSTALL_FAILED_CONFLICTING_PROVIDER
    安卓 文件管理器 各种应用 源码
    android 静音
    android studio 查看大纲
  • 原文地址:https://www.cnblogs.com/feifei0928/p/15091707.html
Copyright © 2020-2023  润新知