vue-router4 路由跳转怎么传递和接收参数?

"vue-router" title="vue-router">vue-router": "^4.1.2",跳转请问如何传参和接收参数

const createCommand = () => {

router.push({

path: "/AddCommand",

query: {

name: "John",

age: 30

},

state: {

isLogin: true

}

})

}

// AddCommand

import { useRouter } from "vue-router"

const router = useRouter()

console.log(router) // 这里没有参数


回答:

import { useRoute } from 'vue-router';

export default {

setup() {

const route = useRoute();

const name = route.query.name;

const age = route.query.age;

const isLogin = route.state.isLogin;

console.log('Name:', name, 'Age:', age);

console.log('IsLogin:', isLogin);

},

};


回答:

useRoute 不是useRouter

以上是 vue-router4 路由跳转怎么传递和接收参数? 的全部内容, 来源链接: utcz.com/p/934207.html

回到顶部