HarmonyOS鸿蒙系统 App(ArkUI)$单引号引用变量失败--解决方法
@State name2:string = '反引号键'

$加大括号来引用变量,不是使用的单引号,而是反引号,在键盘的Esc键的下面




@Entry
@Component
struct Index {
@State message: string = 'Hello World'
@State name2:string = '反引号键'
@State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Blue, Color.Grey, Color.Brown];
build() {
GridRow({
breakpoints: {
value: ['200vp', '300vp', '400vp', '500vp', '600vp'],
reference: BreakpointsReference.WindowSize
}
}) {
ForEach(
this.bgColors, (color, index) => {
GridCol({
span: {
xs: 2, // 在最小宽度类型设备上,栅格子组件占据的栅格容器2列。
sm: 3, // 在小宽度类型设备上,栅格子组件占据的栅格容器3列。
md: 4, // 在中等宽度类型设备上,栅格子组件占据的栅格容器4列。
lg: 6, // 在大宽度类型设备上,栅格子组件占据的栅格容器6列。
xl: 8, // 在特大宽度类型设备上,栅格子组件占据的栅格容器8列。
xxl: 12 // 在超大宽度类型设备上,栅格子组件占据的栅格容器12列。
}
}) //栅格布局
{
Row() {
Text(`${index}`) //
//Text('${this.name2}')
Text(`${this.name2}`)
}.width("100%").height('50vp')
}.backgroundColor(color)
}
)
}
}
}