第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Vuejs 向燒瓶服務器發(fā)送請求,更改 url 并返回原始 json

Vuejs 向燒瓶服務器發(fā)送請求,更改 url 并返回原始 json

桃花長相依 2022-10-27 15:14:14
我有一個用 Python 編寫的服務器 Flask:# configurationDEBUG = TrueUPLOAD_FOLDER = './uploads/'# instantiate the appapp = Flask(__name__)app.config.from_object(__name__)app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER   # enable CORSCORS(app, resources={r'/*': {'origins': '*'}})#Upload@app.route('/')@app.route('/api/uploadFile',methods=['POST'])def uploadFile():    response_object = {'status': 'success'}    response_object['message'] = 'Caricamento effettuato con successo'    file = request.files['file']    filename = secure_filename(file.filename)    file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))    return jsonify(response_object)    # sanity check route@app.route('/ping', methods=['GET'])def ping_pong():    return jsonify('pong')if __name__ == '__main__':    app.run()我有一個上傳文件的 Vuejs 組件:<template>  <div>    <form action = "http://localhost:5000/api/uploadFile" method = "post" enctype="multipart/form-data">      <input type="file" id="file_id" name="file" v-on:change="onFileChange"  value="Choose file" />      <button class="btn btn-success" @click="upload">Upload</button>    </form>  </div></template><script>import axios from 'axios';export default {  name: 'UploadFile',  data() {    return {      file: null,    };  },  methods: {    created() {      this.getBooks();    },    onFileChange(e) {      const files = e.target.files || e.dataTransfer.files;      if (!files.length) { return; }      this.createFile(files[0]);    },    createFile(file) {      const reader = new FileReader();      const vm = this;      reader.onload = (e) => {        vm.file = e.target.result;      };      reader.readAsDataURL(file);    },一切正常(上傳工作正常),但 axios.post 調(diào)用的響應沒有出現(xiàn)在控制臺中!瀏覽器告訴我這個:對于顯示問題的圖像,請單擊此處1我該如何解決這種情況?非常感謝您的幫助
查看完整描述

1 回答

?
元芳怎么了

TA貢獻1798條經(jīng)驗 獲得超7個贊

在您的模板文件輸入中有 id="file_id" 但在您調(diào)用的函數(shù)中

data.append('file', document.getElementById('file').files[0]);

更改為 document.getElementById('file_id').files[0])


查看完整回答
反對 回復 2022-10-27
  • 1 回答
  • 0 關(guān)注
  • 187 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號