el-ui上传文件报错:
response must not be the wildcard '*' when the request's credentials mode is 'include'.
Origin 127.0.0.1:9527 is therefore not allowed access.the credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute
原因是设置了 withCredentials为true,
withCredentials设置为true为 支持发送 cookie 凭证信息,如果报错则去除withCredentials改为
<el-upload
v-model="formFile.file"
class="upload-demo"
<!-- 重点-->
:action="fileUrl"
:headers="headersParams"
<!-- 重点-->
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError"
:limit="1"
:file-list="fileList">
<script>
import { getToken } from '@/utils/auth'
import { FILE_URL } from '@/utils/request'
//某个方法中设置
// 上传地址 FILE_URL 为 http:127.0.0.1:8080
this.fileUrl = FILE_URL + `/api......'
this.headersParams = {
Authorization: this.$store.getters.token
}
</script>