上传导入时,接口需要携带 token ,组件用的是 el-upload ,我们把 token 放到 headers 里即可

<el-upload
  class="upload-demo"
  action="https://jsonplaceholder.typicode.com/posts/"
  :data="importData"
  :show-file-list="false"
  :on-success="handleSuccess"
  :headers="headers"
  >
  <el-button size="small" type="primary">点击上传</el-button>
</el-upload>
<script>
  export default {
    data() {
      return {
        headers:{},
        importData:{imporType: 1},
        token:""
    },
    mouted() {
    	this.token = localStorage.getItem("token")
    	this.headers = {token: this.token}
    }
    methods: {
      handleSuccess(response){
      	if(response.responseCode == 0) {
      		this.$message.success(response.responseMsg)
      	} else {
      		this.$message.error(response.responseMsg)
      	}
      }
    }
  }
</script>
Logo

前往低代码交流专区

更多推荐