首页 > 解决方案 > 在 vuejs 中上传时为空路径

问题描述

我在 vuejs 中处理。

模板:

<b-form @submit.prevent="uploadFile">
  <b-form-file
     v-model="file"
     placeholder="Choose image..."
  />
</b-form>

data() {
  return: {
    file:null
  }
},

methods: {
    uploadFile() {
    console.log(this.file) // result :{$path: "", name: "test2-1591953691.jpeg", lastModified: 1626842100154}
      axios
        .post("/api/upload/store", {
            file: this.file,
        })
        .then((res) => {
          console.log(res.data);
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },

为什么路径为空,有什么方法可以获取路径。请给我一些想法,谢谢。

标签: vue.jsvuejs2

解决方案


推荐阅读