一、AMD處理器win10系統(tǒng)下,DevEco Studio模擬器啟動(dòng)失敗解決辦法。
結(jié)論:在BIOS里面將Hyper-V打開,DevEco Studio模擬器可以成功啟動(dòng)。
二、ArkTS自定義組件導(dǎo)出、引用實(shí)現(xiàn)。
如果在另外的文件中引用組件,需要使用export關(guān)鍵字導(dǎo)出,并在使用的頁面import該自定義組件。
1.自定義組件(被導(dǎo)入組件)
// @ts-nocheck
@Component
struct header {
build() {
Flex({justifyContent:FlexAlign.Center}){
Text('諸子百家').width('100%').height(70).backgroundColor(0x808080).fontColor(0x000000)
}
}
}
export default header
2.組合組件(引用自定義組件)
import router from '@ohos.router';
import header from './header';
let msg:String='index頁面?zhèn)鬟f的消息'
@Entry
@Component
struct Index {
@State message: string = '鴻蒙應(yīng)用狀態(tài)管理出現(xiàn)';
@State isExpanded:boolean=false;
build() {
Row() {
Column() {
header()
if (this.isExpanded){
Text('鴻蒙應(yīng)用狀態(tài)管理消失')
.fontSize(60)
.fontWeight(FontWeight.Bold)
} else {
Text(this.message)
.fontSize(60)
.fontWeight(FontWeight.Bold)
}
Button('跳轉(zhuǎn)')
.onClick(()=>{
this.isExpanded=!this.isExpanded;
router.pushUrl({
url:'pages/Page',
params:{
src:msg
}
})
})
}
.width('100%').height('100%')
}
.height('100%')
}
}
三、@ohos.router (頁面路由)實(shí)現(xiàn)。
1、main_pages.json配置文件配置靜態(tài)路由地址,配置文件路徑:src/main/resources/base/profile/main_pages.json
{
"src": [
"pages/Index",
"pages/Page",
"pages/Twopage"
]
}
2、使用router.pushUrl方法進(jìn)行應(yīng)用內(nèi)頁面路由跳轉(zhuǎn)以及傳值
import router from '@ohos.router';
let msg:String='index頁面?zhèn)鬟f的消息'
@Entry
@Component
struct Index {
build() {
Row() {
Column() {
Button('跳轉(zhuǎn)')
.onClick(()=>{
router.pushUrl({
url:'pages/Page',
params:{
src:msg
}
})
})
}
.width('100%').height('100%')
}
.height('100%')
}
}
3、使用router.getParams()方法進(jìn)接收路由傳值
import router from '@ohos.router';
@Entry
@Component
struct Page {
@State message: string = '子頁面2';
@State src: string=router.getParams()?.['src'];
build() {
Row() {
Column() {
Text(this.message+this.src)
.fontSize(50)
.fontWeight(FontWeight.Bold);
}
.height('100%')
}
}
四、@ohos.router (頁面路由)無法實(shí)現(xiàn)類似Vue的router-view局部渲染方案
1、Vue3的router-view局部渲染方案
2、@ohos.router (頁面路由)是整頁渲染,不能進(jìn)行局部渲染。
五、PersistentStorage:持久化存儲(chǔ)UI狀態(tài)
PersistentStorage:持久化存儲(chǔ)UI狀態(tài)是除了@ohos.data.preferences (用戶首選項(xiàng))之外的,常用的、輕量化、簡(jiǎn)單化的鍵值對(duì)的數(shù)據(jù)存儲(chǔ)方案。
…未完待續(xù)…文章來源:http://www.zghlxwxcb.cn/news/detail-763948.html
本文原創(chuàng),原創(chuàng)不易,如需轉(zhuǎn)載,請(qǐng)聯(lián)系作者授權(quán)。文章來源地址http://www.zghlxwxcb.cn/news/detail-763948.html
到了這里,關(guān)于OpenHarmony鴻蒙原生應(yīng)用開發(fā),ArkTS、ArkUI學(xué)習(xí)踩坑學(xué)習(xí)筆記,持續(xù)更新中。的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!