I have a legacy project built with Laravel 5.2 version, and I am wondering how do setup Vue with it. I have added vue to the package.json file:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"gulp": "^3.9.1",
"laravel-elixir": "^5.0.0",
"bootstrap-sass": "^3.0.0",
"vue": "^2.0.1"
}
}
I have created bootstrap.js and app.js files in resources/assets/js folder:
bootstrap.js
window._ = require('lodash');
/**
* Vue is a modern JavaScript library for building interactive web interfaces
* using reactive data binding and reusable components. Vue's API is clean
* and simple, leaving you to focus on building your next great project.
*/
window.Vue = require('vue');
app.js
require('./bootstrap');
/**
* First we will load all of this project's JavaScript dependencies which
* include Vue and Vue Resource. This gives a great starting point for
* building robust, powerful web applications using Vue and Laravel.
*/
/**
* Next, we will create a fresh Vue application instance and attach it to
* the body of the page. From here, you may begin adding components to
* the application, or feel free to tweak this setup for your needs.
*/
Vue.component('image-input', require('./components/ImageInput.vue'));
const app = new Vue({
el: '#app'
});
And this is the component ImageInput.vue:
<template>
<div>
<div class="row">
<div class="large-6 columns">
<div class="Image-input__image-wrapper">
<i v-show="! imageSrc" class="icon fa fa-picture-o"></i>
<img v-show="imageSrc" class="Image-input__image" :src="imageSrc">
<i v-show="imageSrc" @click="removeImage" class="remove fa fa-times"></i>
</div>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<div class="Image-input__input-wrapper">
Last opp bilder
<input @change="previewThumbnail" class="Image-input__input" name="image" type="file">
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: ['imageSrc'],
methods: {
previewThumbnail: function(event) {
var input = event.target;
if (input.files && input.files[0]) {
var reader = new FileReader();
var vm = this;
reader.onload = function(e) {
vm.imageSrc = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
},
removeImage: function removeImage(e) {
this.imageSrc = '';
document.querySelectorAll('input[type=file]').forEach(element => {
element.value = "";
});
document.getElementById('oldImage').value = '';
}
}
}
</script>
I have setup the gulpfile like this:
elixir(function(mix) {
mix.sass('app.scss')
.browserify('app.js');
});
But, after running gulp command in the terminal I get an error:
gulp-notify: [Laravel Elixir] Browserify Failed!: Unexpected token
/home/vagrant/Projects/flight-park-backend/resources/assets/js/components/ImageInput.vue:1
For:
<template>