npm install xe-ajax vxe-ajax --save
通过 Vue.use() 来全局安装
import Vue from 'vue'
import XEAjax from 'xe-ajax'
import VXEAjax from 'vxe-ajax'
Vue.use(VXEAjax, 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.fetch('/api/user/list').then(response => {
response.json().then(data => {
this.list = data
})
})
}
}
</script>