鍍金池/ 問答/HTML/ axios,post請求問題

axios,post請求問題

我有一個組件,組件里面寫的是axios

import axios from 'axios'

export function POST(URL, params) {
  return new Promise((resolve, reject) => {
    var link = process.env.HOST + URL
    axios({
      method: "POST",
      url: link,
      data: params
    }).then(resolve, reject)
  })
}

現(xiàn)在想在另一個頁面里上傳文件,post請求,現(xiàn)在講這個axios組件引入進來,不會使用,請問如何設置為好?

 <form action="" method="post" enctype="multipart/form-data" id="upload">
        <label>Select file:</label>&nbsp;&nbsp;&nbsp;&nbsp;
        <p class="wrap">
          <input type="file" ref="reffile" name="file" @change="changeselect">
        </p>
        <input class="submit" type="submit" value="Select file" onclick="submitForm($event)"/>
      </form>
        import Axios from '../request/index'
        Vue.prototype.$axios = Axios;

   created(){
        this.$axios.post('url').then(res=>{
          this.data =res.data.message;
          console.log(res)

        })
          .catch(err=>{
            console.log(err)
          })
      }
回答
編輯回答
我不懂

import * as axios from '../request/index'

然后你綁定到vue的prototype上的話,還是在main里綁定比較好

2017年6月13日 10:02
編輯回答
墨小白
import {POST} from '../request/index'

   created(){
    POST('url').then(res=>{
          this.data =res.data.message;
          console.log(res)

        })
          .catch(err=>{
            console.log(err)
          })
      }
2017年10月31日 22:37