1.安装axios:
cnpm i axios -S
2.启动项目:
yarn serve
npm run serve
3.在全局main.js导入axios:
import axios from 'axios'
4.挂载至原型(作用:全局使用):
Vue.prototype.axios = axios
1.安装vue-router:
cnpm i [email protected] -S
2.启动项目:
yarn serve
npm run serve
3.配置路由:
a.导入:
src/router/index.js
import Vue from "vue"
import Router from "vue-router"
import Home from "@/components/Home.vue"
b.注册:
Vue.use(Router)
c.使用:
export default new Router({
routes:[
{
path:'/',
component:Home
}
],
mode:'history'
})
4.在main.js导入挂载
import router from '@/router'
挂载:
new Vue({
router
})