vue-router 怎么用?
1.下载
npm install vue-router@4
2.创建router文件夹 并添加index.js
import { createRouter, createWebHistory ,createWebHashHistory } from 'vue-router'
const routerHistory = createWebHistory()
const routes = [
{
name:'good',
path:'/good',
component:()=>import("../components/goodList/goods")
}
]
const router = createRouter({
history: routerHistory,
routes,
})
export default router
3. 来到main.js
import router from './router'
createApp(App).use(router).mount('#app')
<script setup>
import {useRouter} from "vue-router";
let router = useRouter();
function jumpToGoods() {
router.push({
path: '/good'
})
};
</script>
|