模板
<form @submit.prevent=" addUser()">
<div class="form-group">
<label for="addUser">Password</label>
<input type="tex" class="form-control" id="name" placeholder="Name" name="name" v-model="form.name"
:class="{ 'is-invalid': form.errors.has('name') }">
<has-error :form="form" field="name"></has-error>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="tex" class="form-control" id="email" placeholder="Email" name="email" v-model="form.email"
:class="{ 'is-invalid': form.errors.has('email') }">
<has-error :form="form" field="email"></has-error>
</div>
<div class="form-group">
<label for="picture">Picture</label>
<input type="file" class="form-control" id="image" placeholder="Picture" name="image" >
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</template>
JavaScript
import Form from 'vform'
export default {
name: "Users",
data() {
return {
form: new Form({
name: '',
email: '',
})
}
},
methods: {
addUser() {
this.form.post('/addUser').
then((response) => {
console.log('I clicked');
})
}
}
}
Laravel
$this->validate($request,[
'name'=> 'required',
'email'=> 'required '
]);
$newUser = New NewUser();
$newUser->name = $request->name;
$newUser->email = $request->email;*/
if($request->hasFile('image')){
$imageN = $request->image;
$request->image->storeAs('public/upload',$imageN);
}
$newUser->save();
答案 0 :(得分:0)
图像文件未保存,因为它从未与laravel一起发送。
您可以将图像添加到new Form()
或查看以下有关如何上传图像的帖子:How do I upload image in vuejs?