在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ axios,post請(qǐng)求問(wèn)題

axios,post請(qǐng)求問(wèn)題

我有一個(gè)組件,組件里面寫(xiě)的是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)在想在另一個(gè)頁(yè)面里上傳文件,post請(qǐng)求,現(xiàn)在講這個(gè)axios組件引入進(jìn)來(lái),不會(huì)使用,請(qǐng)問(wèn)如何設(shè)置為好?

 <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上的話(huà),還是在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