透過 100 多個技巧學習 Nuxt!

lodash
nuxt-lodash

具有自動導入和自訂前綴的 lodash 模組

Nuxt 的 Lodash

Version License Types

💡 關於

Lodash 用於 Nuxt 的自動導入模組。

📦 安裝

  1. nuxt-lodash 安裝為開發依賴項
npm i nuxt-lodash -D
  1. 將其添加到您的 nuxt.configmodules 區段中
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