1,鸿蒙DevEco Studio 机测试Failure[INSTALL_FAILED_APP_SOURCE_NOT_TRUSTED]
勾选☑️

勾选自动签名,然后自动跳转登录华为网站,登录即可。

 

 

2.对象字面量须标注类型(升级鸿蒙 next 遇到的问题)


以上TS代码片段展示了没有类型的场景。如果编译器不知道变量point的确切类型,由于对象布局不能确定,编译器无法深度地优化这段代码,造成性能瓶颈。没有类型也会造成属性的类型缺少限制,例如point.x的类型在此时为number,它也可以被赋值成其他类型,造成额外的运行时检查和开销。

在ArkTS中,需要为对象字面量标注类型。

  

来源:初识ArkTS语言 | 华为开发者联盟 

3.网络请求 axios 
升级 Next 之后 ,由于不支持, Any 类型,之前的请求都需要修改。

例如:

export function getCode(tel: string, type: string, area_code: string) {
  return instance.get('/api/v1/get_code', { params: { tel: tel, type: type } });
}

改为:

  return instance.get<string, AxiosResponse<string>, string>('/api/v1/get_code', {
    params: { tel: tel, type: type}
  });

4. json 解析 


需要指定类型;

 

5. json 解析 包含换行符,html符号

举例数据1

var data = "示例:你真好看\n示例:你真漂亮\n" //含有换行的字符串。\n

var obj = JSON.parse(data.replace(/\n/g,"\\n").replace(/\r/g,"\\r"))

举例数据2

解决:
我们通过定位JSON中的:"来寻找字段的value值起始位置(start),再找出结尾的那个"作为value值的结束位置(end),将此之中不表示结尾的双引号全部替换掉。

在我们的场景中,value值是HTML,所以将其中不表示结束位置end的双引号,全部替换为单引号!


                        
原文链接:https://blog.csdn.net/weixin_42541479/article/details/130604227

 

附:(待验证哈)

function escape4Html(json) {
    // Convert the string to a char array
    let temp = Array.from(json);
    // Get the length of the array
    let n = temp.length;
    // Loop through the array
    for (let i = 0; i < n; i++) {
        // Match the :" in JSON
        if (temp[i] === ':' && temp[i + 1] === '"') {
            // Continue looping through the array after :"
            for (let j = i + 2; j < n; j++) {
                // Match the next double quote
                if (temp[j] === '"') {
                    // If the next character after the double quote is not a comma , or a closing curly brace }
                    if (temp[j + 1] !== ',' && temp[j + 1] !== '}') {
                        // Replace the double quote with a single quote ' so that HTML can recognize it
                        temp[j] = "'";
                    } else if (temp[j + 1] === ',' || temp[j + 1] === '}') {
                        // Otherwise, end the current loop and continue processing the next :"
                        break;
                    }
                }
            }
        }
    }
    // Convert the char array back to a string and return it
    return temp.join('');

6.报错To run and debug the Harmony device, configure the HarmonyOS runtime.


网上下载了一个库,导入 Dev Studio 运行 报了以上错误。由于之前的项目是基于open Harmony开发导致的。

修改:

修改:
"products": [
      {
        "name": "default",
        "signingConfig": "default",
        "compileSdkVersion": 10,
        "compatibleSdkVersion": 10,
        "targetSdkVersion": 10,
        "runtimeOS": "OpenHarmony"
      }
    ]
 
为一下内容:
 
 "products": [
      {
        "name": "default",
        "signingConfig": "default",
        "compileSdkVersion": "4.1.0(11)",
        "compatibleSdkVersion": "4.1.0(11)",
        "runtimeOS": "HarmonyOS"
      }
    ]
 

之后在修改:local.properties 为你本地sdk位置即可。

DevEco Studio版本:

DevEco Studio NEXT Developer Preview2

Build Version: 4.1.3.700, built on March 19, 2024

6.报错 App Launch: Failed to get the device apiVersion.


解决:重启模拟器。

 

------------------------------------------------------------------------------------------------------------------------
————————————————

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐