当前位置: 首页 > news >正文

怎么做视频平台网站吗wordpress搬家500错误

怎么做视频平台网站吗,wordpress搬家500错误,怎么建立,品牌设计公司推荐本文探讨了如何将现有的常用架构理论与Arkts和ArkUI结合起来,使代码更有条理,并利用Previewer快速调整布局,同时在不改变代码的情况下运行显示真实数据。 开发环境 Windows 11DevEco Studio 4.0 ReleaseBuild Version: 4.0.0.600, built on…

本文探讨了如何将现有的常用架构理论与Arkts和ArkUI结合起来,使代码更有条理,并利用Previewer快速调整布局,同时在不改变代码的情况下运行显示真实数据。

开发环境

  • Windows 11
  • DevEco Studio 4.0 Release
  • Build Version: 4.0.0.600, built on October 17, 2023

运行环境

  • 华为畅享50Pro
  • HarmonyOS 4.0 API9

初步布局Index

新建一个工程后,首先进入Index页,简单地显示文章列表。

文章数据结构

class Article {title?: stringdesc?: stringlink?: string
}

Index组件

@Entry
@Component
struct Index {@State articles: Article[] = []build() {Row() {Scroll() {Column() {ForEach(this.articles, (item: Article) => {Column() {Text(item.title).fontWeight(FontWeight.Bold)Text(item.desc)Text("----------")}}, (item: Article) => {return item.link})}.width('100%')}}.height('100%')}
}

获取数据

异步请求数据

aboutToAppear()中发送GET请求更新articles数组。

aboutToAppear() {// 请求网络数据axios.get(url).then(response => {// 更新this.articles})
}

分离数据请求和界面逻辑

创建IndexViewModel

将数据请求逻辑移到IndexViewModel中。

@Observed
export default class IndexViewModel {articles?: Array<Article>refreshData() {// 请求网络数据// 更新this.articles}
}

更新Index

@State viewModel: IndexViewModel = new IndexViewModel()aboutToAppear() {this.viewModel.refreshData()
}

使用Mock数据进行预览

IndexViewModelInterface

interface IndexViewModelInterface {articles: Array<Article>refreshData()
}

Mock类

@Observed
export default class IndexViewModelMock implements IndexViewModelInterface {articles: Array<Article> = []refreshData() {this.articles = [{ title: "Mock Title", desc: "Mock Description", link: "mocklink" }]}
}

更新Index以支持Mock数据

@State viewModel: IndexViewModelInterface = new IndexViewModel() // 真实数据
@State viewModel: IndexViewModelInterface = new IndexViewModelMock() // 预览数据

进一步分离UI和数据逻辑

重构IndexContent

build() {Column() {IndexContent({ viewModel: this.viewModel })}
}

Index和IndexPreviewer

@Entry
@Component
struct Index {model: IndexModelBase = new IndexModel()async aboutToAppear() {this.model.refreshData()}build() {Column() {IndexContent({ viewModel: this.model.viewModel })}}
}@Preview
@Component
struct IndexPreviewer {model: IndexModelBase = new IndexModelMock()async aboutToAppear() {this.model.refreshData()}build() {Column() {IndexContent({ viewModel: this.model.viewModel })}}
}

最终架构优化

简化后的Index和IndexPreviewer

@Entry
@Component
struct Index {viewModel: IndexViewModelInterface = new IndexViewModel()async aboutToAppear() {this.viewModel.refreshData()}build() {Column() {IndexContent({ viewModel: this.viewModel })}}
}@Preview
@Component
struct IndexPreviewer {viewModel: IndexViewModelInterface = new IndexViewModelMock()async aboutToAppear() {this.viewModel.refreshData()}build() {Column() {IndexContent({ viewModel: this.viewModel })}}
}

IndexViewModel和IndexViewModelMock实现

@Observed
export default class IndexViewModel implements IndexViewModelInterface {articles: Array<Article> = []title: string = "1"async refreshData(): Promise<void> {this.articles = await this.refreshArticles()this.title = "2"return new Promise(resolve => { resolve() })}async refreshArticles(): Promise<Article[]> {let articles: Array<Article>// 异步请求,返回文章列表return new Promise(resolve => {resolve(articles)})}
}@Observed
export default class IndexViewModelMock implements IndexViewModelInterface {articles: Array<Article> = []title: string = "1"async refreshData(): Promise<void> {this.articles = await this.refreshArticles()this.title = "2"return new Promise(resolve => { resolve() })}refreshArticles(): Promise<Article[]> {return new Promise(resolve => {const articles = [{ title: "Mock Title", desc: "Mock Description", link: "mocklink" }]resolve(articles)})}
}

通过这一系列的优化和重构,使得UI界面与数据逻辑解耦,实现了在Previewer中快速预览布局并使用真实数据运行应用。

http://www.yayakq.cn/news/255141/

相关文章:

  • 化妆品购物网站开发的意义做爰全过程网站免费的视频
  • 如何做网站条幅闪图申请企业邮箱步骤是什么
  • 自己的网站怎么做团购百度seo营销公司
  • 网站营销是什么意思哔哩哔哩网页版打不开
  • 校园门户网站热门推广软件
  • 天津网站设计公司排名海口市龙华区核酸检测
  • 网站制作公司需要什么资质企业网站制作套餐
  • 大学生网站建设规划书十堰吉安营销型网站优化营销
  • 个人网站建设联系电话成都做公众号推广的公司
  • 济宁万达网站建设网课网站
  • wordpress建站产品导入不同目录商丘电子商务网站建设
  • 微博营销案例有哪些wordpress seo 标题
  • 营销型网站开发推广重庆企业网站推广方案
  • 四川建网站世界建筑网站
  • 音乐网站的建设站长工具的使用seo综合查询排名
  • 电子商务网站推广的界定如何做网站毕业设计
  • 可以做旅行行程的网站国外效果做的好的网站
  • 做网站的程序员进什么公司好男生学什么技术最挣钱
  • 扬中网站推广哪家好营销和销售的区别在哪里
  • wap网站制作没有网站可以做淘宝客吗
  • 做ppt的模板的网站有哪些内容怎样做某个网站有更新的提醒
  • 西安企业网站怎么建立wordpress文章自动摘要
  • 网站开发的私活网站短片怎么做
  • 建设通网站登录不进去asp网站怎么做301定向
  • 手游超变传奇网站发布网资源网站优化排名网站
  • 如何做一名优秀的网站管理者网络营销课程总结
  • 深圳做兼职的网站wordpress修改图片
  • 网站建设的公司开发ps做的网站模板
  • 廊坊制作网站公司做婚恋网站赚钱吗
  • ae有么有做gif的网站学网站软件设计