【Vue】iview upload跨域问题
同一个IP
但是端口号不同 也是属于跨域
<FormItem label="交易品种图片"><Upload ref="upload"
name="uploadFile"
:on-success="uploadSuccess"
:headers="headers"
:action="actionurl">
<Button icon="ios-cloud-upload-outline">选择上传文件</Button>
</Upload>
</FormItem>
headers: {'Access-Control-Allow-Origin': '*'
},
//上传图片成功后uploadSuccess(response, file, fileList) {
console.log(response.data);
// console.log(file);
// console.log(fileList);
this.picurl = response.data[0];
},
//上传图片过程
upload() {
for (let i = 0; i < this.uploadFile.length; i++) {
let item = this.file[i]
//console.log(item);
this.$refs.upload.post(item);
}
},
thinkphp6 后台
public function uploads(){
header('Access-Control-Allow-Origin:*');//允许所有来源访问
header('Access-Control-Allow-Method:POST,GET');//允许访问的方式
// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('uploadFile');
//上传到本地服务器
$savename = \think\facade\Filesystem::putFile( 'topic', $file);
}
提示错误
Response for preflight does not have HTTP ok status.
回答
放开options
预检请求的限制。
header('Access-Control-Allow-Method:POST,GET,OPTIONS')
以上是 【Vue】iview upload跨域问题 的全部内容, 来源链接: utcz.com/a/78196.html