我不知道为什么,但如果我在语句中声明它们,似乎我不能调用let
或const
变量if/else
。
if (withBorder) {
const classes = `${styles.circularBorder} ${styles.dimensions} ${styles.circularPadding} row flex-items-xs-middle flex-items-xs-center`;
} else {
const classes = `${styles.dimensions} ${styles.circularPadding} row flex-items-xs-middle flex-items-xs-center`;
}
return (
<div className={classes}>
{renderedResult}
</div>
);
如果我使用此代码,它会说classes is not defined
。
但是,如果我将const
tovar
类更改为已定义,但我会收到有关classes used outside of binding context
和的警告all var declarations must be at the top of the function scope
我怎么能解决这个问题?