路由
This commit is contained in:
21
src/App.vue
21
src/App.vue
@@ -1,17 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="top">
|
||||
|
||||
</div>
|
||||
<router-view></router-view>
|
||||
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.top{
|
||||
width:100vw;
|
||||
height:100vh;
|
||||
background:red;
|
||||
<style lang="scss">
|
||||
*{
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
</style>
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import naive from 'naive-ui'
|
||||
import {router} from "./route"
|
||||
|
||||
createApp(App).use(naive).mount('#app')
|
||||
|
||||
createApp(App).use(naive).use(router).mount('#app')
|
||||
15
src/page/home.vue
Normal file
15
src/page/home.vue
Normal file
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
dksjdksa
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {defineComponent} from 'vue'
|
||||
export default defineComponent({
|
||||
name: 'home',
|
||||
props: {},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
12
src/page/install.ts
Normal file
12
src/page/install.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { App } from 'vue'
|
||||
import home from './home.vue'
|
||||
import login from "./login.vue"
|
||||
home.install = (app: App) => {
|
||||
app.component(home.name, home);
|
||||
}
|
||||
|
||||
login.install = (app: App) => {
|
||||
app.component(login.name, login);
|
||||
}
|
||||
|
||||
export let zujian=[home,login]
|
||||
15
src/page/login.vue
Normal file
15
src/page/login.vue
Normal file
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
login
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {defineComponent} from 'vue'
|
||||
export default defineComponent({
|
||||
name: 'login',
|
||||
props: {},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
36
src/route/index.ts
Normal file
36
src/route/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { createRouter,createWebHashHistory, RouteRecord} from "vue-router";
|
||||
import {zujian} from "../page/install"
|
||||
interface routesgeshi{
|
||||
path:String,
|
||||
name:String,
|
||||
component:object
|
||||
}
|
||||
let routes1 :Array<RouteRecord>=[]
|
||||
|
||||
for(let i in zujian){
|
||||
console.log(i)
|
||||
routes1.push({
|
||||
path:"/"+zujian[i].name,
|
||||
name:zujian[i].name,
|
||||
component:zujian[i]
|
||||
})
|
||||
}
|
||||
console.log(routes1)
|
||||
console.log(zujian, typeof zujian)
|
||||
// const routes = [
|
||||
// // {
|
||||
// // path: "/home",
|
||||
// // name: "home",
|
||||
// // component: zujian.home
|
||||
// // }
|
||||
// // {
|
||||
// // path: "/login",
|
||||
// // name: "login",
|
||||
// // component: login
|
||||
// // },
|
||||
// ]
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: routes1
|
||||
})
|
||||
Reference in New Issue
Block a user