vue搭建项目到axios&element ui引入

1,安装下载nodejs

 http://nodejs.cn/download/

查看node&vue版本

node -v
vue -v

2,npm下载vue&webpack&vue-cli脚手架

npm init vue webpack vue-cli -g

3,创建项目

vue init webpack my-project(项目名)
eslint y/n n
jest y/n n
e2e y/n n
其他回车

4,下载axios和element ui包

npm init axios element ui

5,引入axios和element ui包 

improt axios form 'axios'
import ElementUI from 'element-ui'
import '../node_modules/element-ui/lib/theme-chalk/index.css'(引入element ui样式)
Vue.prototype.axios=axios
axios.defaults.baseURL = 'http://192.168.125.23/pfm/'(设置默认请求路径)
Vue.config.productionTip = false 来关闭生产模式下给出的提示

6,在组件中就可以直接使用this.axios()  

1,
this.axios({
method:"get",
url:"url",
params:{id:1}
}).then(res=>{}).cache(error=>{})
// 如果是get请求的参数对象, 用的是params
// 如果是post请求的参数对象,用的是data
2,
this.axios.get("/user",params:{ id:1})
this.axios.post("/user",{id:1,name:"zs"})

  

  

猜你喜欢

转载自www.cnblogs.com/duhui/p/11784536.html