@rhangai/vue-submit
Vue submit helper
Last updated a month ago by rhangai .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rhangai/vue-submit 
SYNC missed versions from official npm registry.

@rhangai/vue-submit

Helper for requests with confirmation, notification and loading status.

Basic usage

<template>
	<div>
		<div>Name <input v-model="form.name" /></div>
		<div>
			<button :disabled="$submitting.form" @click="submit">Submit</button>
		</div>
		<div v-if="message">
			{{ message }}
		</div>
	</div>
</template>
<script>
export default {
	data: () => ({
		form: {
			name: "John Doe"
		},
		message: ""
	}),
	methods: {
		submit() {
			return this.$submit("form", {
				url: "/my/action",
				data: {
					...this.form
				},
				success: () => {
					this.message = "Success";
				},
				error: () => {
					this.message = "Error";
				}
			});
		}
	}
};
</script>

Instalation

import Vue from "vue";
import { VueSubmit } from "@rhangai/vue-submit";
import axios from "axios";

// Or using full options
Vue.use(VueSubmit, {
	axios,
	confirmation: (vm, confirmation) => {
		// Do something and returns true/false depending on the confirmation
	},
	notify: (vm, result) => {
		// Notify the status
	}
});

Basic setup with buefy

import Vue from "vue";
import { VueSubmit } from "@rhangai/vue-submit";
import axios from "axios";

Vue.use(VueSubmit, {
	axios,
	confirmation(vm, options) {
		return new Promise(resolve => {
			vm.$buefy.dialog.confirm({
				message: options.message || "Are you sure?",
				onCancel: () => resolve(false),
				onConfirm: () => resolve(true)
			});
		});
	},
	notify(vm, { notification, error }) {
		if (error) {
			vm.$buefy.snackbar.open({
				type: "is-danger",
				message: notification.message || "Something went wrong"
			});
		} else {
			vm.$buefy.snackbar.open({
				type: "is-success",
				message: notification.message || "Success"
			});
		}
	}
});

Current Tags

  • 3.0.0-beta.9                                ...           beta (7 days ago)
  • 2.0.8                                ...           latest (a month ago)

19 Versions

  • 3.0.0-beta.9                                ...           7 days ago
  • 3.0.0-beta.8                                ...           20 days ago
  • 3.0.0-beta.7                                ...           24 days ago
  • 3.0.0-beta.6                                ...           24 days ago
  • 3.0.0-beta.5                                ...           a month ago
  • 3.0.0-beta.4                                ...           a month ago
  • 3.0.0-beta.3                                ...           a month ago
  • 3.0.0-beta.2                                ...           a month ago
  • 3.0.0-beta.1                                ...           a month ago
  • 3.0.0-beta.0                                ...           a month ago
  • 2.0.8                                ...           a month ago
  • 2.0.7                                ...           a month ago
  • 2.0.5                                ...           7 months ago
  • 2.0.4                                ...           7 months ago
  • 2.0.3                                ...           7 months ago
  • 2.0.2                                ...           7 months ago
  • 2.0.1                                ...           7 months ago
  • 2.0.0                                ...           7 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 20
Last Day 0
Last Week 10
Last Month 96
Dependencies (0)
None
Dev Dependencies (23)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |