vue 頁(yè)面跳轉(zhuǎn)的實(shí)現(xiàn)方式
<template> <div id=’test’> <button @click=’goTo()’>點(diǎn)擊跳轉(zhuǎn)4</button> </div></template> 2、script
//跳轉(zhuǎn)前頁(yè)面?zhèn)鲄?shù):goTo(item) { //storageData中數(shù)據(jù)用于跳轉(zhuǎn)到下一個(gè)頁(yè)面之后,進(jìn)行返回時(shí)能夠返回到跳轉(zhuǎn)之前的頁(yè)面 let storageData = { searchWords: this.keyWord, pageSize: this.paging.pageSize, pageNo: this.paging.currentPage }; //data中數(shù)據(jù)用于將本頁(yè)面中數(shù)據(jù)通過(guò)跳轉(zhuǎn)功能將其應(yīng)用到下一個(gè)頁(yè)面,與父子組件傳值同理 let data = { type: item.srcType, tableName: item.tableName, name: item.datasourceName, tableId: item.tableId, id: item.datasourceId, }; //將下一個(gè)頁(yè)面中將會(huì)用到的數(shù)據(jù)全部push到$router中 this.$router.push({ //name表示跳轉(zhuǎn)之后的資源前端訪問(wèn)路徑,query用于存儲(chǔ)待使用數(shù)據(jù),其中page是本頁(yè)面name, name: ’onlineSearch’, query: {targetData: data ,storageData, page:’search’, isBackSelect: true, goBackName:’dataSearch’ } }) }3、跳轉(zhuǎn)后的頁(yè)面中獲取上個(gè)頁(yè)面的參數(shù)值
//跳轉(zhuǎn)后頁(yè)面獲取參數(shù):mounted() { //查看是否已經(jīng)參數(shù)是否傳至跳轉(zhuǎn)之后的頁(yè)面,若傳入,則根據(jù)需求進(jìn)行調(diào)用 console.log(this.$route.query.targetData;)}4、從跳轉(zhuǎn)后的頁(yè)面返回跳轉(zhuǎn)前頁(yè)面
//將返回函數(shù)寫(xiě)到methods中g(shù)oBackSheet() { if(this.$route.query.goBackName === ’dataSearch’){ this.$router.push({ name: this.pageName, query: {storageData: this.$route.query.storageData,isBackSelect: true, } }); }}二、router-link跳轉(zhuǎn)1、 通過(guò) to 屬性指定目標(biāo)地址
query相當(dāng)于get請(qǐng)求,頁(yè)面跳轉(zhuǎn)的時(shí)候,可以在地址欄看到請(qǐng)求參數(shù);
query 刷新 不會(huì) 丟失 query里面的數(shù)據(jù);
query要用path來(lái)引入。
params相當(dāng)于post請(qǐng)求,參數(shù)不會(huì)再地址欄中顯示;
params 刷新 會(huì) 丟失 params里面的數(shù)據(jù);
params要用name來(lái)引入。
<!-- 命名的路由 --><router-link :to='{ name: ’user’, params: { userId: 123 }}' @click.native=’goTo’>User</router-link><!-- 帶查詢參數(shù),下面的結(jié)果為 /register?plan=private --><router-link :to='{ path: ’register’, query: { plan: ’private’ }}' @click.native=’goTo’>Register</router-link>2、跳轉(zhuǎn)后頁(yè)面
watch:{ $route(to,from){ //刷新頁(yè)面this.$router.go(1); } }
以上就是vue 頁(yè)面跳轉(zhuǎn)的實(shí)現(xiàn)方式的詳細(xì)內(nèi)容,更多關(guān)于vue 頁(yè)面跳轉(zhuǎn)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. IntelliJ IDEA導(dǎo)入jar包的方法2. SSM框架JSP使用Layui實(shí)現(xiàn)layer彈出層效果3. 刪除docker里建立容器的操作方法4. IntelliJ IDEA導(dǎo)出項(xiàng)目的方法5. Vue 實(shí)現(xiàn)對(duì)quill-editor組件中的工具欄添加title6. JS如何在數(shù)組指定位置插入元素7. .Net中的Http請(qǐng)求調(diào)用詳解(Post與Get)8. java使用xfire搭建webservice服務(wù)的過(guò)程詳解9. PHP下對(duì)緩沖區(qū)的控制10. Java源碼解析之ClassLoader
