이렇게하면 base64로 인코딩 된 이미지가 표시됩니다. 파일을 업로드해야합니다. 어떻게 코드를 변경할 수 있습니다base64 형식이 아닌 vue js에서 이미지를 업로드하는 방법은 무엇입니까?
<script>
submitBox = new Vue({
el: "#submitBox",
data: {
username: '',
category: '',
subcategory: [],
image: '',
},
methods: {
onFileChange(e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
this.createImage(files[0]);
},
createImage(file) {
var image = new Image();
var reader = new FileReader();
var vm = this;
reader.onload = (e) => {
vm.image = e.target.result;
};
reader.readAsDataURL(file);
},
handelSubmit: function(e) {
var vm = this;
data = {};
data['username'] = this.username;
data['category'] = this.category;
data['subcategory'] = this.subcategory;
data['image'] = this.image;
$.ajax({
url: 'http://127.0.0.1:8000/api/add/post/',
data: data,
type: "POST",
dataType: 'json',
success: function(e) {
if (e.status) {
alert("Registration Success")
window.location.href = "https://localhost/n2s/registersuccess.html";
} else {
vm.response = e;
alert("Registration Failed")
}
}
});
return false;
}
},
});
</script>
내 HTML 코드는 내가 할 수 base64 인코딩없이 이미지를 업로드 할 수있는 방법
<div id="submitBox">
<form method="POST" onSubmit="return false;" data-parsley-validate="true" v-on:submit="handelSubmit($event);">
<input name="username" type="text" class="form-control" id="name" placeholder="Name" required="required" v-model="username" data-parsley-minlength="4"/>
<select title="Select" v-model="category" name="category" ref="category">
<option v-for="post in articles" v-bind:value="post.name" >{{post.name}}</option>
</select>
<input class="form-control" type="file" id="property-images" @change="onFileChange">
</form>
</div>
입니까? 이 방법을 사용하면 base64 형식으로 이미지를 업로드 할 수만 있습니다. 파일 업로드 만하면됩니까?
당신은 이것을 이미 요청했습니다. – samayo
어디 .. 제게 해결책을주십시오 – med
이 말은 https://stackoverflow.com/questions/47810962/how-can-i-able-to-upload-picture-using-vue-js입니다. 저는 그것이 오늘이라고 생각했습니다. 그래도 여전히 질문을하지 않았다면 – samayo