Загрузить файл в папку c vuejs - PullRequest
0 голосов
/ 26 марта 2020

хотел бы знать, есть ли способ загрузки файлов в папку publi c с использованием кодирования vuejs У меня есть код, но он создан для перемещения файла в папку laravel publi c. у vuejs есть такая функция?

вот что у меня есть в моей функции. надеюсь, что ваш парень может помочь мне

код формы

<!-- Form Upload -->
            <div class="row">
              <div class="col-sm-6 offset-3">
                <div class="form-group">
                  <label for="exampleFormControlFile1">Upload</label>
                  <input
                    type="file"
                    ref="file"
                    class="form-control-file"
                    @change="onFileChange"
                  >
                  <small class="text-muted">
                    for slideshow images
                    <br />
                     size: 1280 x 630 pixel for good quality
                  </small>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <button
              type="button"
              class="btn btn-primary"
              data-dismiss="modal"
              @click="uploadFile"
              :disabled="disableBtn"
            >Upload</button>
          </div>

код метода

onFileChange(e) {
  this.file = this.$refs.file.files[0];
},
uploadFile() {
  if (this.file == "") {
    this.alertClass = "alert alert-danger";
    this.alertMessage = "Please select a file";
    this.showAlert = true;
  } else {
    this.disableBtn = true;
    this.$parent.showLoading();
    let requestUrl =
      this.baseUrl  + "/media";
    let formData = new FormData();
    formData.append("file", this.file,);
    formData.append("mediatype", this.Mediatype);
    let headers = {
      headers: {
        "Content-Type": "multipart/form-data"
      }
    };

    this.$http
      .post(requestUrl, formData, headers)
      .then(response => {
        this.alertClass = "alert alert-success";
        this.alertMessage = response.data.message;
        this.$refs.file.value = ''
        this.showAlert = true;
        this.$parent.hideLoading();
        this.disableBtn = false;
        this.$parent.getGallery();
      })
      .catch(() => {
        this.disableBtn = false;
        this.$parent.hideLoading();
        this.alertClass = "alert alert-danger";
        this.alertMessage =
          "There is a problem in the request.";
        this.showAlert = true;
      });
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...