Vue 使用 Lodash 打乱数组

136 阅读1分钟

参考

lodash.fill | Lodash中文文档 | Lodash中文网 (lodashjs.com)

环境搭建

安装依赖

安装 lodash:npm i lodash -S

image.png

安装 Ts 支持: npm i @types/lodash -D

image.png

装后重启 vscode 即可

使用

<template>
{{ shuffle }}
</template>

<script setup lang="ts">
import _ from 'lodash'

const arr = [1,2,3,4]
const shuffle = _.shuffle(arr)

</script>

每次刷新页面都会打乱数组

image.png