vite初始化vue3.0项目——配置router和vuex

2021-01-20  本文已影响0人  啥名都不好起

安装构建vue-router

安装相关依赖

yarn add vue-router@next

创建router/index.js文件

import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '@/views/home.vue'

const Router = createRouter({
  history: createWebHashHistory(),
  routes: [{
    path: '/',
    name: 'home',
    component: Home
  }]
})

export default Router


安装构建vuex

安装依赖

yarn add vuex@next

创建store/index.js文件

import { createStore } from 'vuex'

const store = createStore({
  state: {

  },
  getters: {

  },
  mutations: {

  },
  actions: {

  },
  modules: {

  }
})

export default store

在main.js中使用router和store

import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index.js'
import store from './store/index.js'

createApp(App).use(router).use(store).mount('#app')
上一篇下一篇

猜你喜欢

热点阅读