🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
>[success] # 在setup 中使用 Vue router `import { useRouter, useRoute } from 'vue-router' ` 其中`useRouter` 等同于之前`$router`,`useRoute `等同于之前`$route` ~~~ <template> <div @click="goHome">{{ nameRef }}</div> </template> <script> import { ref } from 'vue' import { useRouter, useRoute } from 'vue-router' export default { name: 'about-page', setup() { const nameRef = ref('about 页面') const router = useRouter() const route = useRoute() const goHome = () => { const query = route.query router.push({ path: '/home', query }) } return { nameRef, goHome, } }, } </script> <style></style> ~~~