HarmonyOS URL特殊字符编码

ArkTS中是否有类似URLEncoder的接口可以对URL中的特殊字符进行编码(比如 / % =)?

HarmonyOS
2024-08-27 10:20:43
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

参考TypeScript 语法, 提供了encodeURL 以及 encodeURIComponent 两种编码方式:

@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World'; 
  name: string = "张三"; 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(25) 
          .fontWeight(FontWeight.Bold) 
 
        Button(){ 
          Text('encodeURIComponent') 
            .fontSize(25) 
        } 
        .margin({bottom: 20}) 
        .type(ButtonType.Capsule) 
        .onClick(() => { 
          this.message = "http://huawei.com/index.html?url=" + encodeURIComponent("http://huawei.com?name=" +this.name); 
        }) 
 
        Button(){ 
          Text('encodeURI') 
            .fontSize(25) 
        } 
        .margin({bottom: 20}) 
        .type(ButtonType.Capsule) 
        .onClick(() => { 
          this.message = encodeURI("http://huawei.com/index.html?name=" + this.name); 
        }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-08-27 19:20:04
相关问题
如何处理应用存在的URL编码
592浏览 • 1回复 待解决
HarmonyOS TLV格式编码和解码库
83浏览 • 1回复 待解决
HarmonyOS lottie支持url吗?
66浏览 • 1回复 待解决
如何申请场景化消息特殊权益
1631浏览 • 1回复 待解决
HarmonyOS 图片进行base64编码报错
188浏览 • 1回复 待解决
HarmonyOS web组件加载url失败
88浏览 • 1回复 待解决
HarmonyOS TextEncoder支持ISO-8859-1编码
160浏览 • 1回复 待解决
HarmonyOS imagePacker不支持编码成jpg格式
132浏览 • 1回复 待解决
HarmonyOS字符串替换问题
221浏览 • 1回复 待解决
通过webView修改iframe的URL
626浏览 • 1回复 待解决