vue搭建項目到axios&element ui引入(vue2.9.6)


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 來關閉生產模式下給出的提示
Vue.use(ElementUI)

  

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"})

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM