懒惰的数独——lodash的shuffle方法实现随机打乱的效果

1.效果

2.代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>
</head>
<body>
<div id="app">
    <h1>数独</h1>
    <p>继续[按下]随机按钮直到你获胜</p>

    <button @click="shuffle" style="background-color: chocolate">
        随机改变
    </button>
    <transition-group name="cell" tag="div" class="container">
        <div v-for="cell in cells" :key="cell.id" class="cell">
            {
  { cell.number }}
        </div>
    </transition-group>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            cells: Array.apply(null, { length: 81 })
                .map((_, index) => {
                    return {
                        id: index,
                        number: index % 9 + 1
                    }
                })
        },
        methods: {
            shuffle () {
                this.cells = _.shuffle(this.cells)
            }
        }
    })
</script>
<style>
    .container {
        display: flex;
        flex-wrap: wrap;
        width: 238px;
        margin-top: 10px;
        background-color: coral;
    }
    .cell {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 25px;
        height: 25px;
        border: 1px solid #47a8d0;
        margin-right: -1px;
        margin-bottom: -1px;
    }
    .cell:nth-child(3n) {
        margin-right: 0;
    }
    .cell:nth-child(27n) {
        margin-bottom: 0;
    }
    .cell-move {
        transition: transform 1s;
    }
</style>
</body>
</html>

 利用transition-group和lodash的shuffle方法实现打乱功能

其他代码——小试牛刀的增添数据列表​​​​​​​ 

相关推荐

  1. sparksqlshuffle分区设置

    2023-12-15 06:22:03       40 阅读
  2. loadash常用函数方法

    2023-12-15 06:22:03       40 阅读
  3. 深度比较(lodash isEqual 方法

    2023-12-15 06:22:03       63 阅读
  4. 单例模式:双重效验懒汉实现方式

    2023-12-15 06:22:03       40 阅读
  5. LeetCode 36. 有效

    2023-12-15 06:22:03       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-15 06:22:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-15 06:22:03       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-15 06:22:03       82 阅读
  4. Python语言-面向对象

    2023-12-15 06:22:03       91 阅读

热门阅读

  1. 35、卷积算法总结

    2023-12-15 06:22:03       53 阅读
  2. redis在linux中安装部署

    2023-12-15 06:22:03       64 阅读
  3. Mybatis之缓存

    2023-12-15 06:22:03       58 阅读
  4. 【springboot】【easyexcel】excel文件读取

    2023-12-15 06:22:03       60 阅读
  5. Android 修改状态栏背景半透明显示

    2023-12-15 06:22:03       57 阅读