鸿蒙开发

1、组件渲染问题Foreach
    //最好写上keyGenerator,index导致只显示一个
    ForEach(rollingList, (item: Item) => {
            Column() {
              Text(item).fontSize(12).fontColor(Color.Black)
            }
            .alignItems(HorizontalAlign.Start)
          }, //默认(item,index)=>index+JSON.stringify(item)
            //(item:Item)=>item.id 当其他属性发生改变 列表不会变化
            //哪个属性变化keyGenerator必须有变化才能成功
            ({id,likeNum,isLike}) => JSON.stringify({ id, likeNum, isLike })
)
2、模块(资源)引用,静态可以引用资源resource

如base模块为 src/main/module.json5 type

{
  "module": {
    "name": "base",
    "type": "shared",// 动态为[shared] 静态为[har]
    "description": "$string:shared_desc",
    "deviceTypes": [
      "phone",
      "tablet"
    ],
    "deliveryWithInstall": true,
    "pages": "$profile:main_pages"
  }
}

修改base/hvigorfile.ts system


// 动态
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
 
export default {
system: hspTasks , /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
 
// 静态需修改为:
import { harTasks } from '@ohos/hvigor-ohos-plugin';
 
export default {
system: harTasks , /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */


引用 oh-package.json5

 "dependencies": {
    //静态库
    "@ohos/shareLibrary":"file:../base"
  //动态库
   "base":"file:../base"
  }
3、sharedlibrary模块内使用路由跳转不能直接用'pages/XXPage'

'@bundle:包名(bundleName)/模块名(moduleName)/路径/页面所在的文件名(不加.ets后缀)'

router.pushUrl({
                        url: "@bundle:com.xxx.xxx/xyz/ets/pages/XXPage"
                      }, router.RouterMode.Single).then(()=>{})
                      .catch((err)=>{
                        console.error(`PUSH_URL 错误信息 ${err.code}, message is ${err.message}`)
                      })
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容