HarmonyOS 鸿蒙Next遇到class constructor cannot called without 'new',但检查后并没有发现缺少new的关键字
HarmonyOS 鸿蒙Next遇到class constructor cannot called without ‘new’,但检查后并没有发现缺少new的关键字
import { CommonConstants } from '../../common/constants/CommonConstants'
import DateUtil from '../../common/utils/DateUtil'
import DatepickDialog from './DatePickDialog'
@Component
export default struct StaticCard {
@StorageProp('selectedDate') selectedDate:number=DateUtil.beginTimeOfDay(new Date())
controller:CustomDialogController= new CustomDialogController({
builder:DatepickDialog({selectedDate:new Date(this.selectedDate)})
})
build() {
Column(){
//1.日期
Row(){
Text(DateUtil.formatDate(this.selectedDate)).fontColor($r('app.color.secondary_color'))
Image($r('app.media.ic_public_spinner')).width(20).fillColor($r('app.color.secondary_color'))
}.padding(CommonConstants.SPACE_8)
//2.统计信息
.onClick(()=>{
this.controller.open()
})
}
.width(CommonConstants.THOUSANDTH_940)
.backgroundColor($r('app.color.stats_title_bgc'))
.borderRadius(CommonConstants.DEFAULT_18)
}
}
import { CommonConstants } from '../../common/constants/CommonConstants'
@Component
export default struct DatepickDialog {
controller:CustomDialogController
selectedDate:Date=new Date()
build() {
Column({space:CommonConstants.SPACE_12}){
//1.日期选择
DatePicker({
start: new Date('2020-01-01'),
end: new Date(),
selected: this.selectedDate
})
.onChange((value: DatePickerResult) => {
this.selectedDate.setFullYear(value.year, value.month, value.day)
})
//2.按钮
Row({space:CommonConstants.SPACE_12}){
Button('取消').width(120).backgroundColor($r('app.color.light_gray'))
.onClick(()=>{
this.controller.close()
})
Button('提交').width(120).backgroundColor($r('app.color.primary_color'))
.onClick(()=>{
//1.保存日期到全局
AppStorage.SetOrCreate('selectedDate',this.selectedDate.getTime())
this.controller.close()
})
}
}.padding(CommonConstants.SPACE_12)
}
}
为什么在调用
controller: CustomDialogController = new CustomDialogController({ builder: DatePickDialog({selectedDate: new Date(this.selectedDate)}) })后,我的日期组件就消失了,在preview里面不显示,注解掉这段就正常了,log里面报错class constructor cannot called without ‘new’
更多关于HarmonyOS 鸿蒙Next遇到class constructor cannot called without 'new',但检查后并没有发现缺少new的关键字的实战教程也可以访问 https://www.itying.com/category-93-b0.html
有大佬帮忙看一下嘛?
更多关于HarmonyOS 鸿蒙Next遇到class constructor cannot called without 'new',但检查后并没有发现缺少new的关键字的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
好像不是这个原因,同学同样的代码可以显示出来
我遇到了跟你一样的问题,最后你是怎么处理的
特地登录了来给你点赞,这谁想得到
牛啊