当前位置:   article > 正文

Harmony import和export

harmony import

1、直接在类export 后添加了 default

定义了一个类,直接在类名前添加export default,导入使用时类名不需要放在大括号内

export default class Constants {
  static readonly MATCH_PARENT = '100%'
}

// 导入使用
import Constants from ‘./Constants’   //路径根据文件位置进行处理
TextInput({ placeholder: $r('app.string.username'), text: "11111" })
      .width(Constants.MATCH_PARENT)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2、使用export default +new组合

直接定义类,然后使用export default new +类进行到处,导入使用时类名不需要放在大括号内

class LogUtils {

  private domain: number = 0xFF00
  private format: string = '%{public}s, %{public}s'
  private tag:string="Harmony"

  debug(...args: any[]): void {
    hilog.debug(this.domain, this.tag, this.format, args)
  }

  info(...args: any[]): void {
    hilog.debug(this.domain, this.tag, this.format, args)
  }
}
export default new LogUtils()

// 导
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/240018
推荐阅读
相关标签
  

闽ICP备14008679号