适用于 Nuxt 的 Lodash
💡 关于
📦 安装
- 安装
nuxt-lodash作为开发依赖
npm i nuxt-lodash -D
- 将其添加到您的
nuxt.config的modules部分
export default defineNuxtConfig({
modules: ["nuxt-lodash"],
});
🚀 示例
在您的 Nuxt 应用程序中使用任何 Lodash 方法,它们将被自动导入!
<script setup>
const text = useToUpper("it works!");
</script>
<template>
<div>{{ text }}</div>
</template>
🔨 配置
| 名称 | 默认 | 描述 |
|---|---|---|
prefix | 'use' | 在每个 Lodash 函数前添加的字符串(设置为 false 可禁用) |
prefixSkip | 'is' | 以这些关键字开头的函数将跳过前缀(设置为 false 可禁用) |
upperAfterPrefix | true | 如果为 true,它将自动将前缀后的第一个字母大写(设置为 false 可禁用) |
exclude | [] | 要从自动导入中排除的 Lodash 函数数组 |
alias | [] | 用于重命名特定 Lodash 函数的数组对(前缀仍会添加) |
💻 示例 - 配置
export default defineNuxtConfig({
modules: ["nuxt-lodash"],
lodash: {
prefix: "_",
prefixSkip: ["string"],
upperAfterPrefix: false,
exclude: ["map"],
alias: [
["camelCase", "stringToCamelCase"], // => stringToCamelCase
["kebabCase", "stringToKebab"], // => stringToKebab
["isDate", "isLodashDate"], // => _isLodashDate
],
},
});
📄 许可证
MIT 许可证 © 2021-2022 - Michal Čípa