Skip to content

Instantly share code, notes, and snippets.

@Johnathan
Last active April 5, 2017 13:53
Show Gist options
  • Select an option

  • Save Johnathan/21cabc503572c48d908b585942e392c4 to your computer and use it in GitHub Desktop.

Select an option

Save Johnathan/21cabc503572c48d908b585942e392c4 to your computer and use it in GitHub Desktop.
<template>
<div>
<a href="#" v-bind:class="buttonClass" @click.prevent="submitForm"><slot></slot></a>
<form :action="href" method="POST" ref="form" style="display:none;">
<input type="hidden" name="_method" value="DELETE" />
<input type="hidden" name="_token" :value="csrfToken" />
</form>
</div>
</template>
<script>
export default {
props: [ 'buttonClass', 'href' ],
data() {
return {
csrfToken: document.querySelector('[name=_token]').getAttribute( 'content' )
}
},
methods: {
submitForm() {
if( confirm( 'Are you sure?' ) ) this.$refs.form.submit();
}
}
}
</script>
<destroy-button href="/posts/1" button-class="btn btn-danger">Delete Post 1</destroy-button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment