---
title: "NUXT_B3015"
description: "服务器组件上包含不可序列化的 prop"
canonical_url: "https://nuxt.zhcndoc.com/docs/4.x/errors/b3015"
---
# B3015

模板将函数、类或类实例（例如 `new Date()`）作为 prop 传递给服务器组件，或放入 `<NuxtIsland>` 的 `props` 或 `context` 中。服务器组件的 props 会被序列化为 JSON 并发送到服务器进行渲染，因此这些值无法完整地传递给组件。

除非禁用了 [`experimental.templateDiagnostics`](https://nuxt.zhcndoc.com/docs/4.x/guide/going-further/experimental-features#templatediagnostics)，否则会报告此警告。只会检查模板中可见的值：内联函数、`new` 表达式，以及在 `<script setup>` 顶层声明的函数或类。

## 解决方案

只传递可序列化为 JSON 的值（字符串、数字、布尔值、`null`、数组和普通对象），并将需要该函数的逻辑移到服务器组件中：

```diff [app/pages/index.vue]
 <template>
-  <PriceTag :format="value => `$${value}`" :value="price" />
+  <PriceTag currency="USD" :value="price" />
 </template>
```

如果组件需要使用父组件提供的函数，请在客户端渲染它，而不要将其作为服务器组件。

::read-more{to="https://nuxt.zhcndoc.com/docs/4.x/guide/concepts/server-components"}
::


## Sitemap

See the full [sitemap](https://nuxt.zhcndoc.com/sitemap.md) for all pages.
