HarmonyOS pushPathByName中的第二个参数传入特殊字符串导致异常
解决方案
参考示例如下:
@Entry
@Component
struct NavigationExample {
pageInfo: NavPathStack = new NavPathStack()
@Builder
pageMap(name: string) {
if (name === 'pageOne') {
PageOne()
} else if (name === 'pageTwo') {
PageTwo()
}
}
build() {
Navigation(this.pageInfo) {
Column() {
Button('StartTest', { stateEffect: true, type: ButtonType.Capsule })
.width('80%')
.height(40)
.margin(20)
.onClick(() => {
this.pageInfo.pushPath({ name: 'pageOne' });
})
}
}
.title('NavIndex')
.navDestination(this.pageMap)
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
// PageOne.ets
class TmpClass {
test: string =
'<?ovital_ct name="ovital_sample">{"user":"","birthday":"","sex":"男","Marital_status":false,"work_address":"0"}'
}
@Component
export struct PageOne {
pageInfo: NavPathStack = new NavPathStack();
@State message: string = 'Hello World'
build() {
NavDestination() {
Column() {
Text(this.message)
.width('80%')
.height(50)
.margin(10)
Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule })
.width('80%')
.height(40)
.margin(10)
.onClick(() => {
let tmp = new TmpClass()
this.pageInfo.pushPathByName('pageTwo', tmp, (popInfo) => {
this.message =
'[pushPathByName]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result);
});
})
}.width('100%').height('100%')
}.title('pageOne')
.onReady((context: NavDestinationContext) => {
this.pageInfo = context.pathStack;
})
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
// PageTwo.ets
@Component
export struct PageTwo {
pathStack: NavPathStack = new NavPathStack()
build() {
NavDestination() {
Column() {
Button('popToName', { stateEffect: true, type: ButtonType.Capsule })
.width('80%')
.height(40)
.margin(20)
.onClick(() => {
this.pathStack.popToName('pageOne'); // 将第一个名为name的NavDestination页面移到栈顶,将处理结果传入push的onPop回调中。
})
}.width('100%').height('100%')
}.title('pageTwo')
.onReady((context: NavDestinationContext) => {
this.pathStack = context.pathStack
console.log(JSON.stringify(this.pathStack.getParamByName('pageTwo')))
})
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
HarmonyOS 旋转屏幕,设计宽度的影响 <a name="section17700124317117"></a>
问题描述
基于屏幕设计宽度来进行开发的,目前屏幕设计宽度是 720lpx,都按照这个来的话,当旋转屏幕的时候,按钮突然变大了。对于使用lpx的场景有没有好的解决办法?
HarmonyOS
赞
收藏 0
回答 1
相关问题
HarmonyOS ListItem.swipeAction()的第二个参数edgeEffect不起作用
892浏览 • 1回复 待解决
创建VLAN时,再创建第二个IP地址时显示冲突。
301浏览 • 0回复 待解决
HarmonyOS 无法获取音频设备回调里第二个参数OH_AudioDeviceDescriptorArray中的内容
502浏览 • 1回复 待解决
HarmonyOS OH_Drawing_SetTextStyleLocale (OH_Drawing_TextStyle* , const char* )接口第二个参数
603浏览 • 1回复 待解决
JSUI 怎么在第二个页面修改第一个页面的数据?
5369浏览 • 2回复 待解决
tablist 可不可以默认从第二个开始,如下图所示
770浏览 • 1回复 待解决
HarmonyOS 字符串显示异常
1148浏览 • 1回复 待解决
HarmonyOS 如果有两个span 第一个span放的是中文 第二个span超长 这时候 Ellipsis会展示异常
692浏览 • 1回复 待解决
代码里面Tabs是没有设置index的,添加第二个参数的时候,页面会显示不正常,这个该如何解决?
2217浏览 • 1回复 待解决
HarmonyOS 字符串长度判定异常
460浏览 • 1回复 待解决
HarmonyOS 字符串格式化异常
1484浏览 • 1回复 待解决
HarmonyOS shortcuts配置字符串获取异常
417浏览 • 1回复 待解决
第一个返回true或者false是否影响第二个进入?
1453浏览 • 1回复 待解决
Column 高度设置为 "100%"内部设置两个Row,其中一个高度100,另一个高度"100% "第二个内容会被挤下去?
1453浏览 • 1回复 待解决
应用引用media中的字符串资源如何拼接字符串
270浏览 • 0回复 待解决
判断两个传入的数值或者是字符串是否相等
1148浏览 • 1回复 待解决
在Native侧如何处理ArkTS侧传入的字符串被截断的异常场景
2633浏览 • 1回复 待解决
HarmonyOS 如何实现二级JSON字符串的拼接
724浏览 • 1回复 待解决
为什么调用$r的时候,下面代码中第一个图标能加载出来,第二个加载不出来。不是等价的吗?
2305浏览 • 1回复 待解决
HarmonyOS JSON在转字符串时候对于数据中的特殊字符不会进行防止转义处理么
621浏览 • 1回复 待解决
mysql怎么查询逗号隔开的字符串是否再字段的字符串中?
2617浏览 • 1回复 待解决
ArkUI组件的字符串中如何实现字符串变量拼接
3367浏览 • 1回复 待解决
如何替换字符串中匹配的正则为给定的字符串
895浏览 • 1回复 待解决
如何判断一个字符串是不是JSON字符串?
1438浏览 • 1回复 待解决
判断两个传入的数值或者是字符串是否不相等
1182浏览 • 1回复 待解决
可以根据组件宽度和屏幕宽度的比值换算下,组件宽度请参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-uicontext-V5#ZH-CN_TOPIC_0000001884757690__getrectanglebyid