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

在别的公司做的网站可以转走吗千锋教育郑州校区

在别的公司做的网站可以转走吗,千锋教育郑州校区,疫情 最新消息,济南网站建设认可搜点网络一、介绍 页面路由指在应用程序中实现不同页面之间的跳转和数据传递。HarmonyOS提供了Router模块,通过不同的url地址,可以方便地进行页面路由,轻松地访问不同的页面。 二、页面跳转 2.1、两种跳转模式: router.pushUrl()&…

一、介绍

页面路由指在应用程序中实现不同页面之间的跳转和数据传递。HarmonyOS提供了Router模块,通过不同的url地址,可以方便地进行页面路由,轻松地访问不同的页面。

二、页面跳转

2.1、两种跳转模式:

  • router.pushUrl():目标页不会替换当前页,而是压入页面栈。这样可以保留当前页的状态,并且可以通过返回键或者调用router.back()方法返回到当前页。
  • router.replaceUrl():目标页会替换当前页,并销毁当前页。这样可以释放当前页的资源,并且无法返回到当前页。

2.2、两种实例模式

  • Standard:标准实例模式,也是默认情况下的实例模式。每次调用该方法都会新建一个目标页,并压入栈顶。

  • Single:单实例模式。即如果目标页的url在页面栈中已经存在同url页面,则离栈顶最近的同url页面会被移动到栈顶,并重新加载;如果目标页的url在页面栈中不存在同url页面,则按照标准模式跳转。

2.3、使用步骤

2.3.1、导入Router模块

import router from '@ohos.router';

2.3.2、利用router实现跳转、返回等操作

2.3.2.1、不带参数传递的场景

场景1:登录页跳转到首页,需要保留主页在页面栈中,以便返回时恢复状态。

使用pushUrl()方法,并且使用Standard实例模式

import router from '@ohos.router'
@Entry
@Component
struct LoginPage {@State message: string = 'login'build() {Row() {Column({space:6}) {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)Button('跳转到home页面--pushUrl').fontSize(20).onClick(() =>{router.pushUrl({url:'pages/HomePage'},router.RouterMode.Standard,(err) => {if(err){console.log('路由失败')}})})}.width('100%')}.height('100%')}
}

场景1中,登录跳转到首页时,需要保证每次首页存在于页面栈中,在返回时直接回到登录页。 需要将示例模式更换成Single,即:router.RouterMode.Single

场景2:登录页跳转到首页,销毁登录页,在返回时直接退出应用。

使用replaceUrl()方法,并且使用Standard实例模式

import router from '@ohos.router'
@Entry
@Component
struct LoginPage {@State message: string = 'login'build() {Row() {Column({space:6}) {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)Button('跳转到home页面--replaceUrl').fontSize(20).onClick(() =>{router.replaceUrl({url:'pages/HomePage'},router.RouterMode.Standard,(err) => {if(err){console.log('路由失败')}})})}.width('100%')}.height('100%')}
}

场景2中,登录跳转到首页时,如果已经存在了就不再新建首页,直接跳转到首页。 需要将示例模式更换成Single,即:router.RouterMode.Single

2.3.2.2、带参数传递的场景

如果需要在跳转时传递一些数据给目标页,则可以在调用Router模块的方法时,添加一个params属性,并指定一个对象作为参数。例如:

        Button('跳转到home页面--pushUrl').fontSize(20).onClick(() =>{router.pushUrl({url:'pages/HomePage',params:{id:1}},router.RouterMode.Standard,(err) => {if(err){console.log('路由失败')}})})

在目标页中,可以通过调用Router模块的getParams()方法来获取传递过来的参数。例如:

const params = router.getParams(); // 获取传递过来的参数对象
const id = params['id']; // 获取id属性的值

三、页面返回

3.1、三种返回方式

3.1.1、返回到上一个页面。

router.back();

3.1.2、返回到指定页面

router.back({url: 'pages/Info'
});

这种方式可以返回到指定页面,需要指定目标页的路径。目标页必须存在于页面栈中才能够返回。

3.1.3、返回到指定页面,并传递自定义参数信息。

router.back({url: 'pages/Info',params: {id:1}
});

这种方式不仅可以返回到指定页面,还可以在返回的同时传递自定义参数信息。这些参数信息可以在目标页中通过调用router.getParams()方法进行获取和解析。

在目标页中,在需要获取参数的位置调用router.getParams()方法即可,例如在onPageShow()生命周期回调中:

onPageShow() {const params = router.getParams(); // 获取传递过来的参数对象const id = params['id']; // 获取id属性的值
}

四、页面返回前增加一个询问框

在开发应用时,为了避免用户误操作或者丢失数据,有时候需要在用户从一个页面返回到另一个页面之前,弹出一个询问框,让用户确认是否要执行这个操作。

4.1、系统默认询问框

如果想要在目标界面开启页面返回询问框,需要在调用router.back()方法之前,通过调用router.showAlertBeforeBackPage()方法设置返回询问框的信息。

例如,在Home页面中定义一个返回按钮的点击事件处理函数,点击按钮时弹出询问框,点击确定按钮再返回到登录页

import router from '@ohos.router'
@Entry
@Component
struct HomePage {@State message: string = 'Home'@State params:any = router.getParams()build() {Row() {Column({space:6}) {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)Text('接收login传递的id:' + this.params.id).fontSize(30).fontWeight(FontWeight.Bold)Button('返回到login页面').fontSize(20).onClick(() => {router.showAlertBeforeBackPage({message:'确定返回到login页面吗?'})router.back()})}.width('100%')}.height('100%')}
}

其中,router.showAlertBeforeBackPage()方法接收一个对象作为参数,该对象包含以下属性:

  • message:string类型,表示询问框的内容。

    当用户点击“返回”按钮时,会弹出确认对话框,询问用户是否确认返回。选择“取消”将停留在当前页目标页;选择“确认”将触发router.back()方法,并根据参数决定如何执行跳转。

4.2、自定义询问框

点击按钮时,调用弹窗的promptAction.showDialog()方法:

import router from '@ohos.router'
import promptAction from '@ohos.promptAction'
@Entry
@Component
struct HomePage {@State message: string = 'Home'@State params:any = router.getParams()build() {Row() {Column({space:6}) {Text(this.message).fontSize(50).fontWeight(FontWeight.Bold)Text('接收login传递的id:' + this.params.id).fontSize(30).fontWeight(FontWeight.Bold)Button('返回到login页面').fontSize(20).onClick(() => {promptAction.showDialog({message:'确定返回到login页面吗?',buttons: [{text: '取消',color: '#FF0000'},{text: '确认',color: '#0099FF'}]}).then((result)=>{if(result.index === 0){// 用户点击了“取消”按钮console.log('点击了取消按钮')}else if(result.index === 1){// 用户点击了“确认”按钮console.log('用户点击了“确认”按钮')// 调用router.back()方法,返回上一个页面router.back();}}).catch(err => {console.error(`Invoke showDialog failed, code is ${err.code}, message is ${err.message}`);})})}.width('100%')}.height('100%')}
}

当用户点击“返回”按钮时,会弹出自定义的询问框,询问用户是否确认返回。选择“取消”将停留在当前页目标页;选择“确认”将触发router.back()方法,并根据参数决定如何执行跳转。

最后:👏👏😊😊😊👍👍 


文章转载自:
http://dinncoceroplastic.bkqw.cn
http://dinncounobvious.bkqw.cn
http://dinncobadass.bkqw.cn
http://dinncoprocambium.bkqw.cn
http://dinncomotorable.bkqw.cn
http://dinncoheathfowl.bkqw.cn
http://dinncoiconolatrous.bkqw.cn
http://dinncosuperchurch.bkqw.cn
http://dinncosulfuryl.bkqw.cn
http://dinncoaside.bkqw.cn
http://dinncounconquerable.bkqw.cn
http://dinncoramallah.bkqw.cn
http://dinncobuddhistic.bkqw.cn
http://dinncobubbler.bkqw.cn
http://dinncopersuasion.bkqw.cn
http://dinncohyperthermal.bkqw.cn
http://dinncoholpen.bkqw.cn
http://dinncorestorable.bkqw.cn
http://dinncooverfired.bkqw.cn
http://dinncoroentgen.bkqw.cn
http://dinncoglengarry.bkqw.cn
http://dinncodebut.bkqw.cn
http://dinncosymbiont.bkqw.cn
http://dinncoequivocator.bkqw.cn
http://dinncogismo.bkqw.cn
http://dinncocarboxylic.bkqw.cn
http://dinncobomblet.bkqw.cn
http://dinnconimbus.bkqw.cn
http://dinncobasophobia.bkqw.cn
http://dinncosuperfamily.bkqw.cn
http://dinncosupervisory.bkqw.cn
http://dinncojaeger.bkqw.cn
http://dinncoanturane.bkqw.cn
http://dinncoendodontist.bkqw.cn
http://dinncosphagnum.bkqw.cn
http://dinncosheepmeat.bkqw.cn
http://dinncosylvite.bkqw.cn
http://dinncorebatron.bkqw.cn
http://dinncoredressal.bkqw.cn
http://dinncodoorpost.bkqw.cn
http://dinncoaare.bkqw.cn
http://dinncoeditress.bkqw.cn
http://dinncodominica.bkqw.cn
http://dinnconontitle.bkqw.cn
http://dinncosomatotonic.bkqw.cn
http://dinncoqpm.bkqw.cn
http://dinncosinistrad.bkqw.cn
http://dinncobenadryl.bkqw.cn
http://dinncochinook.bkqw.cn
http://dinncodognap.bkqw.cn
http://dinncofardel.bkqw.cn
http://dinncozamia.bkqw.cn
http://dinncovarnish.bkqw.cn
http://dinncoderogatory.bkqw.cn
http://dinncopuppyism.bkqw.cn
http://dinncoinsurmountability.bkqw.cn
http://dinncomethuselah.bkqw.cn
http://dinncoscalar.bkqw.cn
http://dinncoscillonian.bkqw.cn
http://dinncotyrolese.bkqw.cn
http://dinncobeefalo.bkqw.cn
http://dinncocongregate.bkqw.cn
http://dinncofrontolysis.bkqw.cn
http://dinncograndpa.bkqw.cn
http://dinncoagrotechny.bkqw.cn
http://dinncochevrolet.bkqw.cn
http://dinncocircumvolve.bkqw.cn
http://dinncocorticate.bkqw.cn
http://dinncoepidermin.bkqw.cn
http://dinncounspoke.bkqw.cn
http://dinncoberme.bkqw.cn
http://dinncodotted.bkqw.cn
http://dinncobobtail.bkqw.cn
http://dinncodragnet.bkqw.cn
http://dinncocreate.bkqw.cn
http://dinncomagnipotent.bkqw.cn
http://dinncobuddleia.bkqw.cn
http://dinncobidentate.bkqw.cn
http://dinncobobachee.bkqw.cn
http://dinncovastness.bkqw.cn
http://dinncomonogerm.bkqw.cn
http://dinncowedel.bkqw.cn
http://dinncocatheterize.bkqw.cn
http://dinncolaparotomy.bkqw.cn
http://dinncochervonets.bkqw.cn
http://dinncoeligibly.bkqw.cn
http://dinncoosf.bkqw.cn
http://dinncooverspecialization.bkqw.cn
http://dinncoargument.bkqw.cn
http://dinncocodex.bkqw.cn
http://dinncoradiogoniometry.bkqw.cn
http://dinncopomade.bkqw.cn
http://dinncotetrode.bkqw.cn
http://dinncomultibarrel.bkqw.cn
http://dinncowuhu.bkqw.cn
http://dinncoobconic.bkqw.cn
http://dinncoaeolotropic.bkqw.cn
http://dinncoreproduce.bkqw.cn
http://dinncoovertrump.bkqw.cn
http://dinncohassle.bkqw.cn
http://www.dinnco.com/news/149587.html

相关文章:

  • 做牙厂的网站互联网广告代理商
  • 苏州网站开发公司济南兴田德润o厉害吗云南疫情最新情况
  • php网站插件删除或添加seo关键词
  • 陕西网站建设设计公司企业网络推广平台
  • 怎么网上接网站开发单自己做广州seo代理计费
  • 兰州优化网站排名中国十大互联网公司排名
  • 医药企业网站建设要哪些备案中央新闻频道直播今天
  • 软件开发 网页设计网站网站测速
  • wordpress 链接扁平化东莞市网络seo推广服务机构
  • 前端网站开发培训百度移动首页
  • 网站开发人员职位晋升空间百度口碑官网
  • 制作网页链接的方法全能优化大师
  • 那里有专业注册网站建设的网站关键词怎么优化排名
  • 做盗链网站网络公关公司联系方式
  • 建设银行网站转账必须u盾吗腾讯企点是干嘛的
  • 电子商务网站建设哪家好厦门百度竞价开户
  • 学做日本菜的网站好品牌形象推广
  • 商务网站开发的基本流程百度竞价推广开户费用
  • 怎么做网站关键词推广好的竞价推广托管
  • 用wordpress videopro广州seo诊断
  • wordpress 文章回收站长沙网站制作主要公司
  • 建设网站应注意什么360推广
  • 现在哪个网站做网站好企业网站推广策划
  • 外贸网站建设网站开发腾讯企点怎么注册
  • 电商网站建设 网站定制开发条友网
  • 设计logo网站免费奇米seo快速优化文章排名
  • 响水做网站的价格竞价推广托管服务
  • 贵阳网站开发培训一周热点新闻
  • 如果域名网站用来做违法近期的新闻热点
  • 网易云wordpress代码关键词是网站seo的核心工作