首页 > 编程知识 正文

vue定义路由,vue路由跳转原理

时间:2023-05-03 23:27:30 阅读:41875 作者:65

一、路由跳转

1 .推

在Vue中,this.$router.push (参数)为分页//字符串this.$router.push )/home/first ) /对象this.$ router.pusu 实现的路由this.$router.push (name : ' home (,Params: ) userid:wise ) ) this.$ router.push ) name

this.$router.replace ()用法同上,push )/push和replace之间的差异this.$router.push希望跳转到指定的url路径,并将记录添加到history堆栈中。 单击“后退”返回到上一页的this .但history堆栈中没有记录。 单击“上一步”可跳转到上一页。 //接收参数//script访问this.$ route.query.userid//script访问this.$ route.params.id=1,不重要的可以这样传递密码等还是用params更新页面id还是用params开机自检一样。 跳转后,页面url后面没有参数,但更新页面id后3.router-link消失

//创建路由实例const router=newvue router ({ routes } ) El:'#app ',data: { } ),methods3360 ) } router }出口router-view/router-view router文件夹中的index.js : importvuefrom ' vue ' importvuerouterfrom ' vue-router cont home ).then ) ) module )=resolve(module ) ) }constsupport=) (=resolve(module ) ) consthtmlcssolve htmlCSS ' ).then ) ) ) module ) ) r components/home/JS ' ).then () module )=resolve (module ) } const routes redirect3360 ()/path3360 )、redirect3360 ) 65 redirect3360'/home/htmlCSS'}、{path:'/home '、component 333: htmlCSS} component:JS,},{path:'/support ',component:Support},} const router=newvue router { routes 3:

router-link : to=' { name : ' home ' } ' router-link : to=' { path : '/home ' } '/name, path都可以,因此建议使用path,router-link tag=' Li ' : to=' item.path ' class=' item ' : class=' { BG 3360 ink

//params参数(如post )//路由配置path:(/home/:id )或path: )/home3360id(/path )是首次请求//script保留了this.$ route.params.id router-link tag=' Li ' : to=' { name 3360 ' home ',Params3360{id3360}

//可能是浪费,但如果是浪费,请跳到pushthis.$router.go(n(-1 )//前面或后面n页。 n是正整数或负整数this.$router.go ) ) n )5.location本机js对象

location.href--返回或设置当前文档的URLlocation.search --。 - -返回URL的查询字符串部分。 例如http://www.dreamdu.com/dreamdu.PHP? id=5name=dreamdu返回有哪些? )后面的内容? id=5name=dreamdu location.hash--返回URL后面的内容,如果没有#,则返回URL,如空location.host-- www.dreamdu.com location.host 例如,返回http://www.dreamdu.com :8080/XHTML/return 8080 location.protocol-- URL的协议部分。 例如,http://www.dreamdu.com :8080/XHTML /上一个内容http:location.assign --设置当前文档的URLlocation.replace(- ()

history.go(--前进或后退指定页数,history.go ) ) num; history.back----1返回一页history.forward----1前进一页7 .另外,navigator本机js对象

navigator.userAgent --返回用户代理标题的字符串表示形式,即包含浏览器版本信息等的字符串。 navigator.cookieEnabled --浏览器显示cookie 二、弹窗,就visible控制显示隐藏

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。