在vue中 可以動態(tài)設(shè)置路由參數(shù):
1.使用this.$router.go(),與js histroy.go() 用法一直,前進(jìn)1,后退-1,當(dāng)前頁面:0
注意 使用go時 必須是已經(jīng)有訪問歷史記錄了
案例:
<template> <div> <button @click="goht">后退<button> <br/> <button @click="goqj">前進(jìn)<button> <br/> <button @click="gosx">刷新當(dāng)前<button> </div> </template> <script> export default { methods: { goht(){ this.$router.go(-1); }, goqj(){ this.$router.go(1); }, gosx(){ this.$router.go(0); //或者 this.$router.go(); } } } </script>2.使用push調(diào)用:
案例
<template> <div> <button @click="pageA">去A頁面</button> <br/> <button @click="pageB">去B頁面</button> <br/> </div></template><script> exprot default { methods: { pageA(){ //去路由A頁面,字符串形式只能是path,類似to="path" this.$router.push('/RouterA'); }, pageB(){ //去路由B頁面,數(shù)組形式,類似 :to="{}" this.$router.push( { name: 'RouterB', query: {'name': 'name1', title: 'title1'} //,params:{'name': 'name2', title: 'title2'} } ); } } }</script>總結(jié)
以上所述是小編給大家介紹的Vue 動態(tài)設(shè)置路由參數(shù)的案例分析,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答