【每日学点HarmonyOS Next知识】页面引用问题、Json三方库、路由表使用、下拉刷新问题、视频播放错误
1、HarmonyOS 全屏的自定义组件被其他页面引用后导致其他页面按钮功能无法使用问题?
参考代码:
//1.index.ets
@Entry
@Component
struct First {
@State visible: Visibility = Visibility.None
build() {
// 使用stack可以实现假的dialog覆盖原页面上面
Stack() {
Column() {
Button('页面底层按钮')
.onClick(() => {
// showToast('点击了底层按钮')
console.log('点击了底层按钮', this.visible)
})
.backgroundColor(Color.Blue)
.margin({ top: 200 })
}.width('100%')
.height('100%')
.backgroundColor(Color.Red)
Component1({ visible: $visible })
}.width('100%')
.height('100%')
}
}
//2.Component1.ets
@Component
export struct Component1 {
@Link visible: Visibility
@State btnvisible: Visibility = Visibility.Visible
build() {
Stack() {
Row() {
// 初始页面
Column() {
// 触发dialog的地方
Flex({direction:FlexDirection.Row,justifyContent:FlexAlign.End}){
Button('click')
.type(ButtonType.Normal)
.onClick(() => {
//用于检测点击事件是否透传到原来的页面,我测了一下是没有透传的,符合dialog规范
console.log("hit me!")
if (this.visible == Visibility.Visible) {
this.visible = Visibility.None
this.btnvisible = Visibility.Visible
} else {
this.visible = Visibility.Visible
this.btnvisible = Visibility.None
}
})
.fontColor(Color.White)
.width(80)
.height(80)
}
}
.backgroundColor(Color.Green)
.alignItems(HorizontalAlign.End)
.width(80)
.visibility(this.btnvisible)
}
// .height(50)
.backgroundColor(Color.Yellow)
//这里开始是构造弹窗效果主要需要修改的地方,首先是加了一个半透明灰色的蒙层效果
Column() {
Text('我是弹框内容页面').fontColor(Color.Green)
}
.width('100%')
.height('100%')
.onClick(() => {
if (this.visible == Visibility.Visible) {
this.visible = Visibility.None
this.btnvisible = Visibility.Visible
} else {
this.visible = Visibility.Visible
this.btnvisible = Visibility.None
}
})
// 透明度可以自己调节一下
.opacity(0.7)
.backgroundColor(Color.Orange)
.visibility(this.visible)
}
}
}
2、HarmonyOS 如何解析json内容?有没有更多的json类库?
有自带的json类库吗?只看到一个JSON.parse、JSON.stringify,但是又怎么从json object里读取属性呢?
关于JSON解析与生成的API方法,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-json-V5
JSON三方库相关链接:https://gitee.com/openharmony-sig/tpc_c_cplusplus/tree/master/thirdparty/rapidjson
3、HarmonyOS 系统路由表跟自定义路由如何混用,是否可以提供一个demo?
系统路由表跟自定义路由如何混用
关于自定义路由表和系统路由表混用暂无Demo;具体用法参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-set-navigation-routing-V5
参考该示例代码链接中的 Navigation系统路由:https://developer.huawei.com/consumer/cn/samples/
4、HarmonyOS 下拉刷新后的loading的icon显示在了页面上?
loading的icon在刷新之后会显示在页面的原因有两个:
- Refresh组件的顶部有一部分留白(头像组件空出来的那一行),导致了loading的icon能够显示出来;
- this.RefreshText 的赋值有问题:
.onRefreshing(async () => {
await this.onInitialize
this.isRefreshing = false
this.RefreshText = ''
console.log('onRefreshing test')
})
这里无法将 this.RefreshText 赋值为 ‘’
.onRefreshing(() => {
setTimeout(() => {
this.isRefreshing = false
this.RefreshText = ''
}, 2000)
console.log('onRefreshing test')
})
这里是可以将 this.RefreshText 赋值为 ‘’ 的,在数据请求之后 this.RefreshText 能够赋值成功(不为 ‘加载中…’ ),loading的icon是会自动隐藏的
5、HarmonyOS 视频播放偶现 5400106 错误码?
5400106:不支持的规格错误信息Unsupport format.错误描述:不支持的规格。可能原因:不支持的文件或者格式。处理步骤:当前使用的格式规格不支持,用户需要切换为支持的规格。这部分报错是文件的格式有问题排查一下这个videouri