【Vue初體驗】UI工具+axios與後臺相連
阿新 • • 發佈:2018-11-29
幫學姐寫系統中的一個功能元件,第一次接觸了Vue,感覺很好上手,而且可使用的工具也很多,好記性不如爛筆頭,小小記錄一下~
UI組建庫:Element,個人很喜歡了,好看又好用。
https://element.faas.ele.me/#/zh-CN
axios:一個基於 promise 的 HTTP 庫。https://www.kancloud.cn/yunye/axios/234845
GET方式:
axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
不帶引數
axios
.get("url", {
datatype: "jsonp",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
.then(res => {
console.log(res.data);
//資料在res.data中,此處處理資料
});
POST方式:(使用了qs外掛)
axios .post( "url", qs.stringify({ id: this.id }) ) .then(function(response) { console.log(response); alert("成功!"); }) .catch(function(error) { console.log(error); alert("error!"); });