透過超過 100 個訣竅來學習 Nuxt!

lodash
nuxt-lodash

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

Nuxt 的 Lodash

Version License Types

💡 關於

用於 NuxtLodash 自動導入模組。

📦 安裝

  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>

🔨 設定

名稱預設值描述
prefix'use'在每個 Lodash 函式之前加上字串(停用則設為 false)
prefixSkip'is'以此關鍵字開頭的函式將會跳過前綴(停用則設為 false)
upperAfterPrefixtrue若為 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