parent
8a67f818a8
commit
f029dffb44
9 changed files with 122 additions and 14 deletions
@ -0,0 +1,13 @@ |
||||
<template> |
||||
<div> |
||||
<router-link :to="{name:'options'}">OptionsAPI</router-link> |
||||
| |
||||
<router-link :to="{name:'composition'}">CompositionAPI</router-link> |
||||
</div> |
||||
<div> |
||||
<router-view></router-view> |
||||
</div> |
||||
</template> |
||||
<script setup> |
||||
|
||||
</script> |
@ -0,0 +1,6 @@ |
||||
import {createApp} from "vue"; |
||||
import App from "./App.vue" |
||||
import router from './router' |
||||
import store from './store' |
||||
|
||||
createApp(App).use(router).use(store).mount('#app') |
@ -0,0 +1,32 @@ |
||||
// 引入必要的router组件
|
||||
import {createRouter, createWebHistory} from 'vue-router' |
||||
// 引入视图
|
||||
const OptionsAPI = () => import('../views/OptionsAPIView.vue') |
||||
const CompositionAPI = () => import('../views/CompositionAPIView.vue') |
||||
|
||||
// 引入组件
|
||||
|
||||
|
||||
// 创建路由
|
||||
const routes = [ |
||||
{ |
||||
path: '/options', |
||||
name: 'options', |
||||
component: OptionsAPI |
||||
}, |
||||
{ |
||||
path: '/composition', |
||||
name: 'composition', |
||||
component: CompositionAPI |
||||
}, |
||||
] |
||||
|
||||
// 创建路由器,使用createRouter方法,传入history(路由类型)和 创建好的路由routes
|
||||
// 路由类型分为hash型和html5型,分别为createWebHashHistory和createWebHistory
|
||||
const router = createRouter({ |
||||
history: createWebHistory(), |
||||
routes |
||||
}) |
||||
|
||||
// 导出路由
|
||||
export default router |
@ -0,0 +1,16 @@ |
||||
import {createStore} from "vuex"; |
||||
|
||||
export default createStore({ |
||||
state: { |
||||
count: 1, |
||||
}, |
||||
mutations: { |
||||
|
||||
}, |
||||
actions: { |
||||
|
||||
}, |
||||
modules: { |
||||
|
||||
} |
||||
}) |
@ -0,0 +1,17 @@ |
||||
<template> |
||||
<h3>{{ handleCount }}</h3> |
||||
</template> |
||||
|
||||
<script setup> |
||||
import {computed} from "vue"; |
||||
import {useStore} from "vuex"; |
||||
|
||||
const store = useStore() |
||||
|
||||
const handleCount = computed(() => store.state.count); |
||||
|
||||
</script> |
||||
|
||||
<style scoped> |
||||
|
||||
</style> |
@ -0,0 +1,18 @@ |
||||
<template> |
||||
<h3>{{handleCount}}</h3> |
||||
</template> |
||||
|
||||
<script> |
||||
export default { |
||||
name: "OptionsAPIView", |
||||
computed: { |
||||
handleCount: function () { |
||||
return this.$store.state.count |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style scoped> |
||||
|
||||
</style> |
Loading…
Reference in new issue