From 3c55a471540349ce23021a55a4ab8b6b407ae2fa Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 25 Jul 2017 15:52:54 -0400 Subject: [PATCH] Setup Vue --- package.json | 6 +++- resources/assets/js/app.js | 25 ++++++++++++++- resources/assets/js/bootstrap.js | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 resources/assets/js/bootstrap.js diff --git a/package.json b/package.json index ed3fd1f3f5da..2dac11ad9271 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,9 @@ "sortablejs": "^1.5.1", "sweetalert2": "^6.6.6" }, - "private": true + "private": true, + "dependencies": { + "axios": "^0.16.2", + "vue": "^2.4.2" + } } diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 065a4b3e57f3..6fa634848a25 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -1 +1,24 @@ -var Promise = require('promise') +/** + * Polyfill promises. + */ +const Promise = require('promise') + +/** + * First we will load all of this project's JavaScript dependencies which + * includes Vue and other libraries. It is a great starting point when + * building robust, powerful web applications using Vue and Laravel. + */ + +require('./bootstrap'); + +window.Vue = require('vue'); + +/** + * Next, we will create a fresh Vue application instance and attach it to + * the page. Then, you may begin adding components to this application + * or customize the JavaScript scaffolding to fit your unique needs. + */ + +const app = new Vue({ + el: '#app' +}); diff --git a/resources/assets/js/bootstrap.js b/resources/assets/js/bootstrap.js new file mode 100644 index 000000000000..801462c8043e --- /dev/null +++ b/resources/assets/js/bootstrap.js @@ -0,0 +1,52 @@ +window._ = require('lodash'); + +/** + * We'll load jQuery and the Bootstrap jQuery plugin which provides support + * for JavaScript based Bootstrap features such as modals and tabs. This + * code may be modified to fit the specific needs of your application. + */ + +try { + window.$ = window.jQuery = require('jquery'); + + require('bootstrap-sass'); +} catch (e) {} + +/** + * We'll load the axios HTTP library which allows us to easily issue requests + * to our Laravel back-end. This library automatically handles sending the + * CSRF token as a header based on the value of the "XSRF" token cookie. + */ + +window.axios = require('axios'); + +window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; + +/** + * Next we will register the CSRF Token as a common header with Axios so that + * all outgoing HTTP requests automatically have it attached. This is just + * a simple convenience so we don't have to attach every token manually. + */ + +let token = document.head.querySelector('meta[name="token"]'); + +if (token) { + window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; +} else { + console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); +} + +/** + * Echo exposes an expressive API for subscribing to channels and listening + * for events that are broadcast by Laravel. Echo and event broadcasting + * allows your team to easily build robust real-time web applications. + */ + +// import Echo from 'laravel-echo' + +// window.Pusher = require('pusher-js'); + +// window.Echo = new Echo({ +// broadcaster: 'pusher', +// key: 'your-pusher-key' +// });