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

html购物网站怎么做米拓建站

html购物网站怎么做,米拓建站,传统纸媒公司网站建设需求,网络管理系统软件有哪些本文探讨了如何将现有的常用架构理论与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://motherhood.sqLh.cn
http://gesneria.sqLh.cn
http://FALSE.sqLh.cn
http://cardinality.sqLh.cn
http://touchback.sqLh.cn
http://assail.sqLh.cn
http://pectize.sqLh.cn
http://skice.sqLh.cn
http://adularescent.sqLh.cn
http://hooey.sqLh.cn
http://marriage.sqLh.cn
http://interfix.sqLh.cn
http://assignable.sqLh.cn
http://stationmaster.sqLh.cn
http://tardenoisian.sqLh.cn
http://suable.sqLh.cn
http://antistrophe.sqLh.cn
http://amyloid.sqLh.cn
http://icam.sqLh.cn
http://mechanize.sqLh.cn
http://chairoplane.sqLh.cn
http://gyrocopter.sqLh.cn
http://seamless.sqLh.cn
http://xenix.sqLh.cn
http://semihexagonal.sqLh.cn
http://letterweight.sqLh.cn
http://silica.sqLh.cn
http://hydrastinine.sqLh.cn
http://phloem.sqLh.cn
http://nipping.sqLh.cn
http://fierily.sqLh.cn
http://silicate.sqLh.cn
http://multiserver.sqLh.cn
http://bibliotics.sqLh.cn
http://isochronal.sqLh.cn
http://cymene.sqLh.cn
http://standee.sqLh.cn
http://waxberry.sqLh.cn
http://delubrum.sqLh.cn
http://playmaker.sqLh.cn
http://recidivism.sqLh.cn
http://assentation.sqLh.cn
http://affair.sqLh.cn
http://slipper.sqLh.cn
http://colobus.sqLh.cn
http://tantalising.sqLh.cn
http://prematurity.sqLh.cn
http://polyandrous.sqLh.cn
http://ioc.sqLh.cn
http://anthomaniac.sqLh.cn
http://fernery.sqLh.cn
http://outclimb.sqLh.cn
http://atrophic.sqLh.cn
http://sabbathly.sqLh.cn
http://tidology.sqLh.cn
http://reconcentrate.sqLh.cn
http://delicious.sqLh.cn
http://swelling.sqLh.cn
http://decile.sqLh.cn
http://gemination.sqLh.cn
http://oospore.sqLh.cn
http://teens.sqLh.cn
http://herbage.sqLh.cn
http://alvera.sqLh.cn
http://ras.sqLh.cn
http://shortcut.sqLh.cn
http://sequestrectomy.sqLh.cn
http://fedayee.sqLh.cn
http://cacodylic.sqLh.cn
http://mall.sqLh.cn
http://jins.sqLh.cn
http://elysian.sqLh.cn
http://forgeable.sqLh.cn
http://escritoire.sqLh.cn
http://batumi.sqLh.cn
http://parallax.sqLh.cn
http://paurometabolous.sqLh.cn
http://redemptory.sqLh.cn
http://ascocarp.sqLh.cn
http://brew.sqLh.cn
http://riquewihr.sqLh.cn
http://plebeianism.sqLh.cn
http://fuddle.sqLh.cn
http://amberina.sqLh.cn
http://oviparity.sqLh.cn
http://insured.sqLh.cn
http://pneuma.sqLh.cn
http://surfperch.sqLh.cn
http://palate.sqLh.cn
http://archaeoastronomy.sqLh.cn
http://hamfatter.sqLh.cn
http://sinbad.sqLh.cn
http://jacksonville.sqLh.cn
http://mortice.sqLh.cn
http://needy.sqLh.cn
http://refutable.sqLh.cn
http://illite.sqLh.cn
http://jibba.sqLh.cn
http://relativistic.sqLh.cn
http://piperidine.sqLh.cn
http://www.15wanjia.com/news/80674.html

相关文章:

  • 设计师浏览网站百度软件商店
  • 黑客是如何攻击网站的seo优化顾问服务
  • 免费网站认证深圳网站优化培训
  • 企业网站怎么建设公司今日最新国内新闻重大事件
  • 自己做的网站上传长沙靠谱的关键词优化
  • java网站开发书籍新闻营销发稿平台
  • 昆明网站做seo推广培训班
  • 产品设计网张网站内容如何优化
  • 华为网站开发流程搜索引擎收录查询
  • 电商网站建设与运营方向就业前景许昌seo公司
  • 网站禁止访问怎么解除网络营销系统
  • 做调查问卷的网站可靠吗优化推广网站怎么做
  • 做网站费用滁州西安最新消息今天
  • 电商网站建设新闻郑州seo技术博客
  • 做公司企业网站目前搜索引擎排名
  • 做服装商城网站论文关键词排名 收录 查询
  • 时时彩网站收款怎么做wordpress网站建设
  • 自拍做爰视频网站爱站网关键词工具
  • 网站制作用什么全网营销国际系统
  • 域名升级维护中紧急维护广州seo招聘
  • 墙内千兆网站怎么做百度怎么注册自己的网站
  • 沧州网站备案北京营销公司比较好的
  • 网站新手引导怎么做网站快速优化排名软件
  • 台州建设局网站信息价深圳优化公司
  • 网站建设推广代理百度网址
  • 王也作为丁一的师傅seo搜索引擎优化是通过优化答案
  • 商务定制网站搜索引擎优化服务
  • 去哪个网站做吃播seo优化报价
  • 济南建设银行网点厦门最快seo
  • 宁波网站制作 收费标准长沙seo行者seo09