我不知道为什么,但似乎我不能调用 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到 var类是定义,但我得到一个关于 classes used outside of binding context和 all var declarations must be at the top of the function scope的警告
我该怎么补救?