this.$router.push({path:"/demo",query:{id:1}});
console.log(this.$route.query);刷新【路由展示参数】,刷新不丢失pq
this.$router.push({name:"demo",params:{id:1}});
console.log(this.$route.params);刷新【路由不展示】传递参数消失np;
对路由的封装,无论如何都展示在路由中,刷新参数不丢失
1.在main.js封装方法
1.1 $jump
//刷新页面参数都不会消失
Vue.prototype.$jump = ({ url, params = {}, name, type = 'push' } = {}) => {
//使用name传递参数
if (name) {
currentVue.$router[type]({
name,
query: params
})
}
//使用path传递参数
if (url) {
currentVue.$router[type]({
path: url,
query: params
})
}
}
1.2 currentVue
const currentVue = new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
1.3页面使用
click() {//路由展示 使用path传递参数--刷新页面不消失
let url = "/test";
this.$jump({