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>
🔨 配置
名稱 | 預設 | 描述 |
---|---|---|
前綴 | 'use' | 在每個 Lodash 函式前預先加入的字串(false 停用) |
前綴跳過 | 'is' | 以這些關鍵字開頭的函式將會被前綴跳過(false 停用) |
前綴後大寫 | true | 如果為 true,它將自動將前綴後的第一個字母大寫(false 停用) |
排除 | [] | 要從自動導入中排除的 Lodash 函式陣列 |
別名 | [] | 用於重新命名特定 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