用于 Vue 全局安装 xe-ajax
AMD 安装
require.config({
paths: {
'xe-ajax': './dist/xe-ajax.min',
'vxe-ajax': './dist/vxe-ajax.min'
}
})
define(['vue', 'xe-ajax', 'vxe-ajax'], function (Vue, XEAjax, VXEAjax) {
Vue.use(VXEAjax, XEAjax, {context: true})
})
NPM 安装
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)
示例
./Home.vue
<template>
<div>
<ul>
<li v-for="(item, index) in list" :key="index">{{ item.name }}</li>
</ul>
</div>
</template>
<script>
export default {
data () {
return {
loading: false,
list: []
}
},
created () {
this.init()
},
methods: {
init () {
this.loading = true
this.$ajax.getJSON('/api/user/list').then(data => {
this.loading = false
this.list = data
}).catch(e => {
this.loading = false
})
}
}
}
</script>
License
Copyright (c) 2017-present, Xu Liangzhan