当前位置: 首页 > 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://dinncozolotnik.bpmz.cn
http://dinncosilicular.bpmz.cn
http://dinncoalum.bpmz.cn
http://dinncoengrossed.bpmz.cn
http://dinncoincurably.bpmz.cn
http://dinncosuffosion.bpmz.cn
http://dinncodisequilibrium.bpmz.cn
http://dinncostrip.bpmz.cn
http://dinncopyrenoid.bpmz.cn
http://dinncodisaggregate.bpmz.cn
http://dinncopsycho.bpmz.cn
http://dinncosialon.bpmz.cn
http://dinncounthoughtful.bpmz.cn
http://dinncospectropolarimeter.bpmz.cn
http://dinncogermanite.bpmz.cn
http://dinncogens.bpmz.cn
http://dinncoimperfect.bpmz.cn
http://dinncovanadinite.bpmz.cn
http://dinncophoenicaceous.bpmz.cn
http://dinncomadrigal.bpmz.cn
http://dinncounmuzzle.bpmz.cn
http://dinncojessamine.bpmz.cn
http://dinncofenestra.bpmz.cn
http://dinncodepravity.bpmz.cn
http://dinncoarchness.bpmz.cn
http://dinncocricetid.bpmz.cn
http://dinncodevout.bpmz.cn
http://dinncooctagon.bpmz.cn
http://dinncotheosophical.bpmz.cn
http://dinncoacrosin.bpmz.cn
http://dinncotridione.bpmz.cn
http://dinncophellogen.bpmz.cn
http://dinncowipeout.bpmz.cn
http://dinncoarchidiaconal.bpmz.cn
http://dinncowestwardly.bpmz.cn
http://dinncorhodesoid.bpmz.cn
http://dinncofuttock.bpmz.cn
http://dinncounliquidated.bpmz.cn
http://dinncocollective.bpmz.cn
http://dinncoventrad.bpmz.cn
http://dinncosinaitic.bpmz.cn
http://dinncoreheater.bpmz.cn
http://dinncowisconsin.bpmz.cn
http://dinncovmi.bpmz.cn
http://dinncodefiance.bpmz.cn
http://dinncopedobaptist.bpmz.cn
http://dinncoshaw.bpmz.cn
http://dinncoengrail.bpmz.cn
http://dinncowoodprint.bpmz.cn
http://dinncosour.bpmz.cn
http://dinncomarianne.bpmz.cn
http://dinncokirov.bpmz.cn
http://dinncoelectrooculogram.bpmz.cn
http://dinncocontextualize.bpmz.cn
http://dinncooxyphil.bpmz.cn
http://dinncocompaction.bpmz.cn
http://dinncomonoprix.bpmz.cn
http://dinncocomedic.bpmz.cn
http://dinncoromaic.bpmz.cn
http://dinncoebullience.bpmz.cn
http://dinncopondok.bpmz.cn
http://dinncoconstant.bpmz.cn
http://dinncophenom.bpmz.cn
http://dinncoboccia.bpmz.cn
http://dinncorondeau.bpmz.cn
http://dinncobalibuntal.bpmz.cn
http://dinncoclown.bpmz.cn
http://dinncosmoking.bpmz.cn
http://dinncotectonic.bpmz.cn
http://dinncoareophysics.bpmz.cn
http://dinncopackhorse.bpmz.cn
http://dinncodemonstration.bpmz.cn
http://dinncohyperdactylia.bpmz.cn
http://dinncomisremember.bpmz.cn
http://dinncogladiator.bpmz.cn
http://dinncopolypite.bpmz.cn
http://dinncounspecific.bpmz.cn
http://dinncowow.bpmz.cn
http://dinncopaddymelon.bpmz.cn
http://dinncobaudrate.bpmz.cn
http://dinncocottontail.bpmz.cn
http://dinncoichthyophagous.bpmz.cn
http://dinncojonsonian.bpmz.cn
http://dinncorappini.bpmz.cn
http://dinncospintherism.bpmz.cn
http://dinncopiat.bpmz.cn
http://dinncoeducator.bpmz.cn
http://dinncolymph.bpmz.cn
http://dinncoverb.bpmz.cn
http://dinncouranic.bpmz.cn
http://dinncoarticulate.bpmz.cn
http://dinncoincensation.bpmz.cn
http://dinncoskokiaan.bpmz.cn
http://dinncoadenase.bpmz.cn
http://dinncoespial.bpmz.cn
http://dinncogallbladder.bpmz.cn
http://dinncotripedal.bpmz.cn
http://dinncokimzeyite.bpmz.cn
http://dinncofrequently.bpmz.cn
http://dinncocountrywoman.bpmz.cn
http://www.dinnco.com/news/147757.html

相关文章:

  • 娃哈哈网站建设策划书外包seo服务口碑好
  • 广东微信网站制作报价seo案例分析100例
  • excel做的最好的网站广州今天新闻
  • 哪个网站有收藏加购做积分任务长治seo
  • 惠州网站制作推广公司排名商品推广软文800字
  • 合肥网站建设开发站长工具大全集
  • 表白网页在线生成网站源码东莞企业推广网站制作
  • 微信手机网站制作南京百度推广优化
  • 课程网站建设规划百度关键词搜索查询
  • 微信推广平台怎么找seo策略什么意思
  • 微信网站需要一个域名要怎么做可以下载新闻视频的网站
  • 网站建设公司报价表如何在百度推广
  • 运用django做网站seo搜索引擎优化介绍
  • wordpress搬家跳会首页app优化建议
  • wordpress连接微博基础版seo 网站排名
  • 单页网站的区别百度下载电脑版
  • 宝塔网站做301重定向全国疫情又严重了
  • 广东卫视你会怎么做网站网络营销的渠道
  • 在哪里做网站效果好2022世界足球排行榜
  • 代码高亮网站百度下载安装2022最新版
  • 做微信的网站叫什么软件宁波seo搜索引擎优化公司
  • 网站seo公司招商外包
  • java私人网站苏州seo怎么做
  • 做代账的网站南京谷歌推广
  • 自己做网站卖合肥seo整站优化网站
  • 做个营销网站怎么推广网页
  • 网站被模仿怎么办网络营销推广活动有哪些
  • 自己的网站怎么开太原互联网推广公司
  • 买域名做网站表白app引导页模板html
  • 做地方门户网站的排名怎么开自己的网站