@
molvqingtai 确实是 proxy,刚用代码试了。
```
<script setup lang="uts">
import { ref, toRaw } from 'vue'
// 定义类型( uts 是强类型语言,需要类型定义)
interface SkuSpecValue {
name: string
value: string
}
interface SkuGood {
sku_spec_values: SkuSpecValue[]
}
interface GoodType {
id: string | Array<any> // 注意:id 可能变为数组引用
sku_goods: SkuGood[]
}
// 创建响应式引用
const good = ref<GoodType>({
id: "1",
sku_goods: [{
sku_spec_values: [
{ name: "颜色", value: "红色" }
]
}]
})
// 创建响应式引用 - 注意:这里直接引用 good.value.sku_goods
const client_classify = ref(good.value.sku_goods)
// 设置 id 为 client_classify 的引用
good.value.id = client_classify.value
// 序列化
const jsonString = JSON.stringify(good.value)
console.log('Serialized:', jsonString)
// 以下是修复
// 批量转换为原始对象 来自:deepseek
function convertAllToRaw(obj) {
if (Array.isArray(obj)) {
return obj.map(item => {
if (item && typeof item === 'object') {
return convertAllToRaw(toRaw(item))
}
return item
})
} else if (obj && typeof obj === 'object') {
const result = {}
for (const key in obj) {
const value = obj[key]
if (value && typeof value === 'object') {
result[key] = convertAllToRaw(toRaw(value))
} else {
result[key] = value
}
}
return result
}
return obj
}
const jsonStringFix = JSON.stringify(
convertAllToRaw(good.value)
)
console.log("fixed",jsonStringFix)
</script>
```

自己封装个 JSON.stringify 函数来修复就行。