gpt4 book ai didi

javascript - Laravel 5.2 - vue 集成

转载 作者:行者123 更新时间:2023-12-01 02:33:19 26 4
gpt4 key购买 nike

我有一个使用 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"
}
}

我在 resources/assets/js 文件夹中创建了 bootstrap.jsapp.js 文件:

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'
});

这是组件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!: Unexpected token

/home/vagrant/Projects/flight-park-backend/resources/assets/js/components/ImageInput.vue:1

对于:

<template>

最佳答案

关于javascript - Laravel 5.2 - vue 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48151143/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com