vue相關ajax庫
相關庫:
vue-resource: vue插件, 多用於vue1.x
axios: 第三方庫, 多用於vue2.x
vue-resource使用
// 引入模塊
import VueResource from ‘vue-resource‘
// 使用插件
Vue.use(VueResource)
// 通過vue/組件對象發送ajax請求
this.$http.get(‘/someUrl‘).then((response) => {
// success callback
console.log(response.data) //返回結果數據
}, (response) => {
// error callback
console.log(response.statusText) //錯誤信息
})
axios使用
// 引入模塊
import axios from ‘axios‘
// 發送ajax請求
axios.get(url)
.then(response => {
console.log(response.data) // 得到返回結果數據
})
.catch(error => {
console.log(error.message)
})
vue相關ajax庫