webpack-Vue project
Create project
You may encounter permission problems when using NPM to install related component dependencies. In this case, you can run in PowerShell administrator mode; Start menu-> right-click-> Windows PowerShell (administrator)
Create a project named v_music
# 使用 webpack 打包工具初始化一个名为 v_music 的工程
vue init webpack v_music
Install dependencies
We need to install four plugins: vue-router, element-ui, vue-axios, sass-loader and node-sass
# 进入工程目录
cd v_music
# 安装 vue-router
npm install vue-router --save-dev
# 安装 element-ui
npm i element-ui -S
# 安装 axios
npm install --save axios vue-axios
# 安装 SASS 加载器
npm install sass-loader node-sass --save-dev
# 安装依赖
npm install
Start the project
npm run dev
running result
Open http: // localhost: 8080 in the browser and you will see the following effect
Attachment: NPM related command description
- npm install moduleName: install the module to the project directory
- npm install -g moduleName: -g means to install the module to the global, which location is installed on the disk, depends on the location of npm config prefix
- npm install -save moduleName: --save means install the module to the project directory and write dependencies in the dependencies node of the package file, -S is the abbreviation of the command
- npm install -save-dev moduleName: --save-dev means install the module into the project directory and write dependencies in the devDependencies node of the package file, -D is the abbreviation of the command
Source code
Configure routing
-
Create routing table
-
Create a router folder under src and create index.js in it, this file is a routing table
-
import Vue from 'vue' import VueRouter from "vue-router"; import Login from "../views/login"; // 安装路由 Vue.use(VueRouter); // 配置路由 export default new VueRouter({ routes:[ { //路由路径 path:'/login', //路由名称 name:'Login', //跳转到组件 component:Login } ] })
-
-
Configure the routing table in main.js
-
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import VueRouter from 'vue-router' //全局使用路由模块 // 导入上面创建的路由配置目录 import router from './router' Vue.use(VueRouter); /* eslint-disable no-new */ new Vue({ el: '#app', //配置路由 router, components: { App }, template: '<App/>' })
-
-
Create a routing view in App.vue
-
<template> <div id="app"> <router-view>首页</router-view> </div> </template> <script> export default { name: 'App' } </script> <style> </style>
-