国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue Router攜帶并接收query、params參數(shù)方式

這篇具有很好參考價(jià)值的文章主要介紹了Vue Router攜帶并接收query、params參數(shù)方式。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

攜帶query參數(shù)

  1. 傳遞參數(shù)
    【方式一:通過查詢字符串直接拼接在路徑后面】
    【方式二:傳遞一個(gè)對象,路徑是path屬性,拼接的參數(shù)是query屬性,推薦】

    <template>
    	<div>
    		<ul>
    			<li v-for="item in dataList" :key="item.id">
    				<!-- 方式一:模板字符串拼接 -->
    				<router-link :to="`/list/detail?id=${item.id}&title=${item.title}&content=${item.content}`">進(jìn)入{{item.title}},查看詳情</router-link>
    				<!-- 方式二:對象寫法 -->
    				<router-link :to="{
    					path: '/list/detail',
    					query: {
    						id: item.id,
    						title: item.title,
    						content: item.content
    					}
    				}">進(jìn)入{{item.title}},查看詳情</router-link>
    			</li>
    		</ul>
    		<router-view></router-view>
    	</div>
    </template>
    <script>
    	name: 'List',
    	data() {
    		return {
    			dataList: [{
    				id: 1,
    				title: '標(biāo)題1'content: '內(nèi)容1'
    			}, {
    				id: 2,
    				title: '標(biāo)題2',
    				content: '內(nèi)容2'
    			}, {
    				id: 3,
    				title: '標(biāo)題3',
    				content: '內(nèi)容3'
    			}]
    		}
    	}
    </script>
    
  2. 接收參數(shù)
    【直接在$route.query中獲取】

    <template>
    	<div>
    		<p>id:{{$route.query.id}}</p>
    		<p>標(biāo)題:{{$route.query.title}}</p>
    		<p>內(nèi)容:{{$route.query.content}}</p>
    	</div>
    </template>
    <script>
    export default {
    	name: 'Detail'
    }
    </script>
    

攜帶params參數(shù)

  1. router/index.js
    【需要在router中配置path、name】
    import Vue from 'vue';
    import VueRouter from 'vue-router';
    Vue.use(VueRouter);
    export default new VueRouter({
    	routes: [{
    		name: 'xiangqing',
    		path: '/detail/:id/:title/:content',   // 需要通過這種方式給參數(shù)占個(gè)坑
    		component: 'Detail'
    	}]
    });
    
  2. 傳遞參數(shù)
    <template>
    	<div>
    		<router-link to="/detail/001/標(biāo)題/內(nèi)容">進(jìn)入詳情</router-link>  <!-- 字符串方式 -->
    		<router-link :to="{
    			name: 'xiangqing',
    			params: {
    				id: '001',
    				title: '標(biāo)題',
    				content: '內(nèi)容'
    			}
    		}">進(jìn)入詳情</router-link> <!-- 使用對象方式時(shí),只能使用name屬性,不能使用path -->
    	</div>
    </template>
    
  3. 接收參數(shù)
    <template>
    	<div>
    		<p>id: {{$route.params.id}}</p>
    		<p>標(biāo)題:{{$route.params.title}}</p>
    		<p>內(nèi)容:{{$route.params.content}}</p>
    	</div>
    </template>
    

上述接收參數(shù)的方式存在代碼冗余,利用props方式接收query、params參數(shù),簡化代碼

  1. 在router/index.js中配置props屬性

    import Vue from 'vue';
    import VueRouter from 'vue-router';
    import List from '@/pages/List';
    import Detail from '@/pages/Detail'
    Vue.use(VueRouter);
    export default new VueRouter({
    	routes: [{
    		path: '/list',
    		component: List,
    		children: [{
    			path: 'detail',
    			component: Detail,
    			props: true,    // props設(shè)置為true,在組件中只能接收params方式傳過來的參數(shù),query參數(shù)無法獲取
    			props($route) {  // props為函數(shù),功能強(qiáng)大,query、params參數(shù)都可以獲取
    				return {
    					id: $route.query.id,
    					title: $route.query.title,
    					content: $route.query.content
    				}
    				// 或者
    				return {
    					id: $route.params.id,
    					title: $route.params.title,
    					content: $route.params.content
    				}
    			}
    		}]
    	}]
    });
    
  2. 接收參數(shù)文章來源地址http://www.zghlxwxcb.cn/news/detail-642531.html

    <template>
    	<div>
    		<p>id: {{id}}</p>
    		<p>title: {{title}}</p>
    		<p>content: {{content}}</p>
    	</div>
    </template>
    <script>
    export default {
    	name: 'Detail',
    	props: ['id', 'title', 'content']
    }
    </script>
    

到了這里,關(guān)于Vue Router攜帶并接收query、params參數(shù)方式的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Element UI 頁面?zhèn)鲄⑴c接收參數(shù),注意router和route

    在 Element UI 中,可以使用 $router 對象來進(jìn)行頁面跳轉(zhuǎn)并設(shè)置請求參數(shù)。同時(shí),也可以在目標(biāo)頁面中使用 $route 對象來獲取傳遞的參數(shù)。 以下是一個(gè)示例: 在跳轉(zhuǎn)前的頁面中,使用 $router 對象進(jìn)行跳轉(zhuǎn)并設(shè)置參數(shù): 在這個(gè)例子中,跳轉(zhuǎn)前的頁面通過 $router 對象的 push 方法進(jìn)行

    2024年01月18日
    瀏覽(20)
  • [Vue Router warn]: Discarded invalid param(s) “id“ when navigating. Seexxxxxxxfor more details

    [Vue Router warn]: Discarded invalid param(s) “id“ when navigating. Seexxxxxxxfor more details

    ?警告信息建議訪問的鏈接 場景: 當(dāng)我 在vue3 組合式api中嘗試使用name+params去路由跳轉(zhuǎn)并傳遞參數(shù)的時(shí)候,出現(xiàn)警告信息,并且接收不到params的參數(shù)。代碼如下: a頁面跳轉(zhuǎn)b頁面 點(diǎn)擊鏈接查看到更新日志 也就是說,從Vue Router的2022-8-22 這次更新后,我們使用上面的方式在新頁

    2024年02月07日
    瀏覽(13)
  • vue路由及參數(shù)router

    vue路由及參數(shù)router

    1.1 如果還沒安裝node.js, 則先安裝node.js ,安裝完成后,查看node版本 1.2 安裝淘寶鏡像, 安裝完成后查看npm版本:npm -v 1.3 安裝webpack 1.4 安裝vue全局腳手架,vue-cli2.x使用 npm install -g vue-cli , vue-cli3.x使用 npm install -g @vue/cli 安裝, 查看vue版本: vue -V 1.5 準(zhǔn)備工作做好了,開始正

    2024年01月23日
    瀏覽(20)
  • react 11之 router6路由 (兩種路由模式、兩種路由跳轉(zhuǎn)、兩種傳參與接收參數(shù)、嵌套路由,layout組件、路由懶加載)

    react 11之 router6路由 (兩種路由模式、兩種路由跳轉(zhuǎn)、兩種傳參與接收參數(shù)、嵌套路由,layout組件、路由懶加載)

    npm i react-router-dom 兩種模式 Router:所有路由組件的根組件,包裹路由的最外層容器 Link:跳轉(zhuǎn)路由組件 Routes :用于定義和渲染路由規(guī)則( 用于替換 Switch 組件) Route:路由規(guī)則匹配組件,顯示當(dāng)前規(guī)則對應(yīng)的組件 exact = 精確匹配,只有當(dāng) path 和 pathname 完全匹配時(shí)才會展示該路由

    2024年02月12日
    瀏覽(27)
  • vue3上傳多個(gè)文件并攜帶參數(shù)一起上傳,后臺java接收

    vue3上傳多個(gè)文件并攜帶參數(shù)一起上傳,后臺java接收

    直接上代碼 vue代碼 上傳文件組件,采用element-plus 這里采用的是手動(dòng)上傳,選取文件后,點(diǎn)擊保存才會觸發(fā)上傳操作 這個(gè)地方如果不添加.raw? 可以看到這個(gè)files是個(gè)[object Object] 同樣它傳入后臺是個(gè)String類型 你用MultipartFile[]來接收這個(gè)String類型的 “[object Object]” 這肯定不行

    2024年02月13日
    瀏覽(20)
  • 利用vue-router跳轉(zhuǎn)的幾種方式

    ?1 router-link 2 this.$router.push ? ? 跳轉(zhuǎn)到指定路徑,并將跳轉(zhuǎn)頁面壓入history棧中,也就是添加了一個(gè)頁面記錄。 3 this.$router.replace ? ? 跳轉(zhuǎn)到指定路徑,將history棧中的當(dāng)前頁面替換為跳轉(zhuǎn)到的頁面。 4 this.$router.go(n) ? ? 在histroy棧中向前或者向后跳轉(zhuǎn)n個(gè)頁面,n可為正整數(shù)或負(fù)

    2024年02月12日
    瀏覽(26)
  • vue3中使用route、router、store的方式

    route: ?(1) vue3寫法: ?(2) vue2寫法: ?router: ?(1) vue3寫法: ?(2) vue2寫法: ?store: ?(1) vue3寫法: ?(2) vue2寫法:

    2024年02月13日
    瀏覽(45)
  • Vue3——getCurrentInstance、頁面中route和router的獲取方式

    Vue3——getCurrentInstance、頁面中route和router的獲取方式

    getCurrentInstance() 在vue2中,可以通過this來獲取組件實(shí)例,但是在vue3的setup函數(shù)中,無法通過this獲取到組件實(shí)例,在setup函數(shù)中this的值是undefined,但是vue3提供了getCurrentInstance()來獲取組件的實(shí)例對象; 輸出結(jié)果: ?可以看出,getCurrentInstance是一個(gè)方法,getCurrentInstance()是一個(gè)對

    2024年02月15日
    瀏覽(17)
  • Vue-router 3.x 參數(shù)傳遞看完讓你明明白白!

    Vue-router 3.x 參數(shù)傳遞看完讓你明明白白!

    Vue- routrer,頁面路由跳轉(zhuǎn)時(shí),攜帶參數(shù)傳遞 并拿取傳遞過來的參數(shù),本文將詳細(xì)講解 Vue router傳遞參數(shù)的多種方式; 如果你還不了解 Vuerouter 基本使用及配置請通過下面?zhèn)魉烷T,了解vue router 路由的基本配置及使用 傳送門去了解 Vue-router params參數(shù)傳遞也有兩種方式:第一種就

    2024年02月06日
    瀏覽(18)
  • vue使用axios發(fā)送post請求攜帶json body參數(shù),后端使用@RequestBody進(jìn)行接收

    vue使用axios發(fā)送post請求攜帶json body參數(shù),后端使用@RequestBody進(jìn)行接收

    最近在做自己項(xiàng)目中,做一個(gè)非常簡單的新增用戶場景,但是使用原生axios發(fā)送post請求的時(shí)候,還是踩了不少坑的。 唉,說多了都是淚,小小一個(gè)新增業(yè)務(wù),在自己前后端一起開發(fā)的時(shí)候,硬是搞了好久。 下面就把問題總結(jié)分享下,防止后人再踩坑。 首先先看下我的接口定

    2024年02月02日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包