Skip to content

Files

Latest commit

 

History

History
54 lines (36 loc) · 921 Bytes

vue-ajax.md

File metadata and controls

54 lines (36 loc) · 921 Bytes
title
Vue 中使用 ajax

发送 ajax 请求

:::tip AjaxPlugin 插件依赖于 axios 详细 API 文档请查看:axios :::

版本要求

AjaxPluginvux@^2.1.0-rc.20开始支持

引入

main.js 入口文件中引入:

import { AjaxPlugin } from 'vux'
Vue.use(AjaxPlugin)

兼容性问题

需要注意的是axios是基于Promise的,因此如果你需要兼容低版本浏览器(caniuse),需要引入polyfill

Polyfill 推荐使用 es6-promise

require('es6-promise').polyfill()

全局使用

Vue.http.post('/api').then()

组件中使用

export default {
  created () {
    this.$http.post('/api').then(({data}) => {
      console.log(data)
    })
  }
}