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