1.0.4 • Published 6 years ago
vue-ajax-handler v1.0.4
vue-ajax-handler
Ultra minimal generic vue component to deal with ajax loading
Usage
Adapted from: https://adamwathan.me/renderless-components-in-vuejs/
Perform an ajax call and delegate the rendering to:
loadingslot when loadingthe default slot passing data as parameter in case of success.
errorslot in case of error passing error as parameter in case of error.
This a generic library with no dependency on ajax library, so
- The component parent should provide a get function that will be called with the given url.
<ajax-handler url="https://api.github.com/orgs/vuejs/repos">
<template #default="{data}">
<p>{{data.data[0].name}}</p>
</template>
</ajax-handler>import { ajaxHandler } from 'AjaxHandler'
import { get } from "axios";
export default {
components: {
ajaxHandler
},
inject: {
get
}
}API
ajax-handler
slots
loadingslot to render loading feedbackerrorslot to render error feedbackdefaultslot to render data when loaded. Receives data as parameter.
props
urlString (required)The url used to make ajax request.
methods
load()Perform an ajax call. Automatically called by created hook.
Installation
npm install vue-ajax-handlerProject setup
npm installCompiles and hot-reloads for development
npm run serveCompiles and minifies for production
npm run buildRun your tests
npm run testLints and fixes files
npm run lintRun your unit tests
npm run test:unitCustomize configuration
Update the API section of README.md with generated documentation
npm run doc:build