我有一个使用 Laravel 5.2 版本构建的遗留项目,我想知道如何用它设置 Vue。我已经将 vue 添加到 package.json 文件中:
{
"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"
}
}
我在资源/资产/js 文件夹中创建了bootstrap.js
和app.js
文件:
引导.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');
应用.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'
});
这是组件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>
我已经像这样设置了gulpfile
:
elixir(function(mix) {
mix.sass('app.scss')
.browserify('app.js');
});
但是,在终端中运行gulp命令后,我收到一个错误:
gulp-notify: [Laravel Elixir] Browserify Failed!: 意外令牌
/home/vagrant/Projects/flight-park-backend/resources/assets/js/components/ImageInput.vue:1
为:
<template>
你试过laravel-elixir-vueify吗?https://github.com/JeffreyWay/laravel-elixir-vueify/blob/master/readme.md