VladikOtez

Piece of Vue On Rails Config

Jun 10th, 2017
642
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Vue.use(VueResource);
  2. import Vue from 'vue'
  3. import TurbolinksAdapter from 'vue-turbolinks'
  4. import VueResource from 'vue-resources'
  5.  
  6. document.addEventListener('turbolinks:load', () => {
  7.     Vue.http.headers.common['X-CSRF-token'] = document.querySelector('meta[name = "csrf-token"]').getAttribute('content')
  8.     var element = document.getElementById('team-form');
  9.   if (element != null) {
  10.       var team = JSON.parse(element.dataset.team);
  11.       var players_attributes = JSON.parse(element.dataset.playersAttributes);
  12.       players_attributes.forEach(function (player) {
  13.         player._destroy = null;
  14.       });
  15.       var app = new Vue({
  16.         el: element,
  17.           mixins: [TurbolinksAdapter],
  18.           data: function () {
  19.               return {team: team}
  20.           }
  21.  
  22.       })
  23.  
  24.       console.log(app)
  25.   }
  26. })
RAW Paste Data