npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shaynekasai/v-fetch

v1.1.4

Published

A Vue directive to add AJAX to your app without the boilerplate

Downloads

29

Readme

LinkedIn Stargazers License NPM

Summary

v-fetch is a directive that adds AJAX functionality to your Vue 2 application so that you don't have to write all of the boilerplate code to call a simple API request to update a model or submit data to an end-point. The goal of v-fetch is to reduce the amount of code in your components and provide a more intuitive interface to making HTTP requests.

Note: This is a work in progress, so the code and API is likely to change quickly.

Installation

npm install @shaynekasai/v-fetch --save

Usage

First, import and use v-fetch:

import VueFetch from 'v-fetch'

Vue.use(VueFetch);

Simple GET example:

<a href="/api/endpoint" v-fetch v-on:click.prevent>click</a>

Simple GET example that updates a model from the AJAX return call:

<span>{{ message }}</span>
<a href="/api/endpoint" v-fetch="{updateModel: 'message'}" v-on:click.prevent>click</a>

Important! when using updateModel, make sure your end-point returns data using the same name. If you want to access a nested value in the json that is returned from your end-point, see the returnField option below

Simple form example that sends foo as json to /api/endpoint:

<form method="post" action="/api/endpoint" v-fetch>
  <input type="hidden" name="foo" value="bar">
</form>

Form POST example that sends formModel data as json and updates the message data from the return request:

<span>{{ message }}</span>
<a href="/api/endpoint" v-fetch:post="{sendModel: 'formModel', updateModel: 'message'}" v-on:click.prevent>click</a>

API

Methods:

v-fetch:get|post|put|patch|delete

Options:

  • updateModel: '<string>' - the Vue model property to update
  • sendModel: '<string>' - the Vue model to send over as a form, json, or query args
  • sendAs: 'json|form' - send data as json data or as FormData
  • returnField: '<string>' - gets the value from your json end-point using dot notation (arrays/more complex notation not supported yet)
  • eventType: '<string>' - the event type to use
  • extraParams: <object> - these get merged into fetch's extra options.
  • onStart: '<string>' - calls your method just before the ajax call
  • onComplete: '<string>' - calls your method after ajax call is completed
  • onError: '<strong> - calls your method if there's an error

Examples

Here are some codepen examples where you can see how this all works:

Callbacks

onStart - before async call is made, includes params used in fetch

onComplete - after async call is made, includes params used in fetch

onError - on async error, call is made, includes params used in fetch

Events

v-fetch:start

v-fetch:complete