HarmonyOS url如何进行URL编码和解码?

HarmonyOS
2025-01-09 13:59:41
2942浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

参考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 = encodeURIComponent("http://example.com?name=" +this.name);
        })

        Button(){
          Text('decodeURIComponent')
            .fontSize(25)
        }
        .margin({bottom: 20})
        .type(ButtonType.Capsule)
        .onClick(() => {
          this.message = decodeURIComponent(this.message);
        })


        Button(){
          Text('encodeURI')
            .fontSize(25)
        }
        .margin({bottom: 20})
        .type(ButtonType.Capsule)
        .onClick(() => {
          this.message = encodeURI("http://example.com/index.html?name=" + this.name);
        })

        Button(){
          Text('decodeURI')
            .fontSize(25)
        }
        .margin({bottom: 20})
        .type(ButtonType.Capsule)
        .onClick(() => {
          this.message = decodeURI(this.message);
        })
      }
      .width('100%')
    }
    .height('100%')
  }
}
  • 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.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
分享
微博
QQ
微信
回复
2025-01-09 17:04:05


相关问题
HarmonyOS URL编码问题
482浏览 • 1回复 待解决
HarmonyOS TLV格式编码和解码
617浏览 • 1回复 待解决
实现文本的编码和解码机制。
899浏览 • 1回复 待解决
HarmonyOS URL特殊字符编码
1502浏览 • 1回复 待解决
HarmonyOS URL的gbk解编码
355浏览 • 1回复 待解决
如何处理应用存在的URL编码
1550浏览 • 1回复 待解决
如何进行解码操作,有人知道吗?
923浏览 • 1回复 待解决
如何进行base64编码,有人知道吗?
1149浏览 • 1回复 待解决
对指定url的图片进行下载保存
1866浏览 • 1回复 待解决
HarmonyOS uri编码解码问题
513浏览 • 1回复 待解决
HarmonyOS 如何拦截web加载url
590浏览 • 1回复 待解决
HarmonyOS url 无法传+号
451浏览 • 1回复 待解决
HarmonyOS lottie支持url吗?
790浏览 • 1回复 待解决
HarmonyOS 关于URL的问题
893浏览 • 1回复 待解决
恭喜您,今日已阅读两篇内容,特奖励+2声望, 快来领取吧。