【发布时间】:2022-11-25 10:46:35
【问题描述】:
在下面的代码中,当我通过 props 在函数 getserversideprops 中返回一个类对象时,在页面函数中变量是未定义的,就像下面的代码一样
`
export default function cars(obj){
return <h1>counter: {obj.counter}</h1> // obj is undefined, why??
}
export async function getServerSideProps({req,res}){
class Counter{
constructor(){
this.counter = 22
}
}
var counter = new Counter()
return {
props:
{
obj:JSON.stringify(counter)
}
}
}
`
我期望页面参数对象将具有对象计数器而不是未定义的
【问题讨论】:
标签: next.js compiler-errors getserversideprops