当前位置:   article > 正文

vue el-upload 上传接口增加 token_el-upload 添加token

el-upload 添加token

上传导入时,接口需要携带 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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/283655
推荐阅读
相关标签
  

闽ICP备14008679号