user.js
export default {
login(phone, password) {
},
registered(phone, password) {
}
...
}
category.js
export default {
addCategory(categoryId) {
},
deleteCategory(categoryId) {
}
...
}
index.js
// import user from './user.js'
// import category from './category.js'
/* export default {
user,
category
} */
export {default as user} from './user.js'
export {default as category} from './category.js'
vue中使用
main.js全局注册
import API from '@/request/index.js'
Vue.prototype.$API = API
index.vue中使用
// 发送请求
const {phone, password} = this
this.$API.user.login(phone, password).then(res => {
// 成功的操作
}).catch(err => {
// 失败的操作
})