前端2021: vue3.0项目的环境搭建__Vue.js
发布于 7 天前 作者 banyungong 205 次浏览 来自 分享
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利

更新脚手架cli

npm install -g [@vue](/user/vue)/cli  cli升级到4版本

vueCli 创建项目

vue create vue-next-jsapp

为项目check Router Vuex 等所需插件

enter键进入: choose Vue version

选择特性feature

创建项目ing

启动项目

cd vue-next-jsapp
npm run serve 

项目目录

vuex store

import { createStore } from 'vuex'

export default createStore({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
  }
})

router/index.js

import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router

使用插件main.js

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

createApp(App).use(store).use(router).mount('#app')

```<p style="line-height: 20px; color: #ccc">
        版权声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
        作者: GeekQiaQia
        原文链接:<a href='https://juejin.im/post/6915728178359042056'>https://juejin.im/post/6915728178359042056</a>
      </p>
回到顶部