npm install xe-ajax --save

vue2.x 中:

import Vue from 'vue'
import XEAjax from 'xe-ajax'

Vue.prototype.$ajax = XEAjax

vue3.x 中:

import app from '../app'
import XEAjax from 'xe-ajax'

app.config.globalProperties.$ajax = XEAjax

使用

<template>
  <ul>
    <li v-for="(item, index) in list" :key="index">{{ item.name }}</li>
  </ul>
</template>
<script>
export default {
  name: 'App',
  data: {
    return {
      list: []
    }
  },
  created () {
    this.$ajax.get('/api/user/list').then(data => {
      this.list = data
    })
  }
}
</script>

abc26296
172 声望24 粉丝