fjc0k / taro-axios

在 Taro 中使用 axios。

Home Page:https://www.npmjs.com/package/taro-axios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

如何上传文件

vinurs opened this issue · comments

参照readme里面的用例我没有能跑起来,我这里有个api接口upload,这个用axios应该怎么写?
https://api-scaffold.dieya.net/api/api-docs/index.html

<Button
        className='button'
        onClick={async () => {
          Taro.chooseImage({
            success (res) {
              const tempFilePaths = res.tempFilePaths
              Taro.uploadFile({
                url: 'https://api-scaffold.dieya.net/api/example/upload', //仅为示例,非真实的接口地址
                filePath: tempFilePaths[0],
                name: 'file',
                // formData: {
                //   'user': 'test'
                // },
                success (res){
                  const data = res.data
                  console.log("res is ", res)
                  //do something
                }
              })
            }
          })
         

        }}>
        <Text>上传文件</Text>
      </Button>

我直接用taro上传是可以的,但是换成taro-axios不知道应该怎么写
image

最近又重新试了一下,貌似又好了