Nuxt Medusa
適用於 Nuxt 的 Medusa 模組。
功能
- 支援 Nuxt 3
- 對
@medusajs/js-sdk
的封裝 - 實用的可組合函式,例如
useMedusaClient
- 在 API 伺服器路由中使用
serverMedusaClient
- 支援 TypeScript
快速設定
- 將
@nuxtjs/medusa
依賴項新增到你的專案
npx nuxi@latest module add medusa
- 建立一個包含以下
MEDUSA_URL
變數的 .env 檔案
MEDUSA_URL=<YOUR_MEDUSA_URL> # By default https://:9000
就是這樣!你現在可以在 Nuxt 中從 Medusa 獲取資料了 ✨
<script setup lang="ts">
const client = useMedusaClient();
const { products } = await client.store.product.list();
</script>
如果你在使用 Medusa 時遇到 CORS
問題,請確保 medusa-config.js
檔案中的 process.env.STORE_CORS
指向你的本地 Nuxt 專案。預設情況下,Medusa 將 CORS 設定為 https://:8000
,而 Nuxt 預設執行在 https://:3000
開發
# Install dependencies
yarn
# Generate type stubs
yarn dev:prepare
# Develop with the playground
yarn dev
# Build the playground
yarn dev:build
# Run ESLint
yarn lint
# Run Vitest
yarn test
yarn test:watch
# Release new version
yarn release