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}`)
})