43.HarmonyOS鸿蒙系统 App(ArkUI)@State$单引号引用变量失败--解决方法

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)
      }
      )
    }
  }
}
相关推荐
IT陈图图9 小时前
优雅管理,智慧阅读:基于 Flutter × OpenHarmony 构建图书馆读者列表模块
flutter·华为·鸿蒙·openharmony
小白阿龙10 小时前
鸿蒙+flutter 跨平台开发——简易井字棋小游戏实现
flutter·华为·harmonyos·鸿蒙
夜雨声烦丿10 小时前
Flutter 框架跨平台鸿蒙开发 - 打造随机抽奖/点名器应用
flutter·华为·harmonyos
弓.长.10 小时前
React Native 鸿蒙跨平台开发:实现商品列表组件
react native·react.js·harmonyos
以太浮标10 小时前
华为eNSP模拟器综合实验- ospf区域的作用和报文类型的关系解析
网络·华为·智能路由器
小白阿龙11 小时前
鸿蒙+flutter 跨平台开发——Placeholder 控件的基础使用场景
flutter·华为·harmonyos·鸿蒙
时光慢煮11 小时前
基于 Flutter × OpenHarmony 图书馆管理系统之构建书籍管理模块
flutter·华为·开源·openharmony
弓.长.11 小时前
React Native 鸿蒙跨平台开发:SafeAreaView 安全区域
安全·react native·harmonyos
弓.长.11 小时前
React Native 鸿蒙跨平台开发:i18n 国际化方案代码指南
react native·react.js·harmonyos
南村群童欺我老无力.11 小时前
Flutter 框架跨平台鸿蒙开发 - 打造专业级单位换算器,支持8大类50+单位互转
flutter·华为·harmonyos