在vue中 可以動態設置路由參數:
1.使用this.$router.go()
,與js histroy.go()
用法一直,前進1,后退-1,當前頁面:0
注意 使用go時 必須是已經有訪問歷史記錄了
案例:
<template> <div> <button @click="goht">后退<button> <br/> <button @click="goqj">前進<button> <br/> <button @click="gosx">刷新當前<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調用:
案例
<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頁面,數組形式,類似 :to="{}" this.$router.push( { name: 'RouterB', query: {'name': 'name1', title: 'title1'} //,params:{'name': 'name2', title: 'title2'} } ); } } } </script>
總結
以上所述是小編給大家介紹的Vue 動態設置路由參數的案例分析,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com