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