A Vue.js plugin for getting CSRF-token
yarn add vue-csrf
or
npm install vue-csrf --save
Import package
import VueCsrf from 'vue-csrf';
Vue.use(VueCsrf);
or with options
import VueCsrf from 'vue-csrf';
Vue.use(VueCsrf, {
selector: 'meta[name="csrf-token"]', // selector of csrf element with csrf-token value
attribute: 'content', //attribute of csrf-token element
});
then you can get csrf-token by next commands
this.$csrfToken;
Vue.csrfToken;
this.$csrf.get();
Vue.csrf.get();
Also you can set new value by
this.$csrf.set('new_csrf');
Vue.csrf.set('new_csrf');