我不知道为什么,但如果我在if/else
语句中声明let
或const
个变量,我似乎无法调用它们.
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
类更改为var
类,但我会收到关于classes used outside of binding context
和all var declarations must be at the top of the function scope
的警告
我怎样才能解决这个问题?