简体   繁体   English

VSCode ${ 在 React Native 中<text>显示错误</text>

[英]VSCode ${ inside a React Native <Text> shows error

I must have changed something somewhere in my VSCode because it's showing me an error for this code:我必须在我的 VSCode 中的某个地方进行了更改,因为它向我显示了此代码的错误: 在此处输入图像描述

The code is:代码是:

<Text>
    ${item.final_price / 100}
</Text>

In this case, it should print a dollar value, like "$100" where the $ sign in this case is textual and the brackets here contain a variable.在这种情况下,它应该打印一个美元值,例如“$100”,其中 $ 符号在这种情况下是文本的,并且这里的括号包含一个变量。

When hovering on top of the red warning, there's no explanation for the error given.当悬停在红色警告上方时,没有对给出的错误进行解释。 When adding a line break between $ and {item.final_price / 100} , the error is gone, but saving it puts them back together (prettier removes the line break, as it should).${item.final_price / 100}之间添加换行符时,错误消失了,但保存它会将它们重新组合在一起(更漂亮的会删除换行符,因为它应该)。

This is probably a tsconfig/prettier declaration which is wrong or something like that.这可能是一个错误的 tsconfig/prettier 声明或类似的东西。 Any ideas?有任何想法吗?

try this尝试这个

<Text>
{"$" + (item.final_price / 100)}
</Text>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM