Vue-axios post 跨域问题
问题描述问题解决方案headers: {"Content-Type": "application/x-www-form-urlencoded"}添加上述
·
问题描述
问题解决方案
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
添加上述?代码即可!
!!! 还有个重点问题,关于提交表单,要使用qs
1. 添加qs 插件 npm install qs --save-dev
2. 使用
3. 代码
<script>
import qs from "qs";
export default {
data() {
return {
form: {
scheduleName: "",
scheduleAddr: "",
scheduleTime: ""
}
};
},
methods: {
backScheduleList() {
this.$router.replace({
path: "/schedule-list"
});
},
onSubmit() {
let params = {
scheduleName: this.form.scheduleName,
scheduleAddr: this.form.scheduleAddr,
scheduleTime: this.form.scheduleTime
};
params = qs.stringify(params);
this.$axios
.post("http://domla.xyz:8080/member/schedule", params, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
.then(response => {
if (response.data.code == 200) {
this.$message({
type: "success",
message: "添加成功!"
});
} else {
this.$message({
type: "error",
message: "添加失败!"
});
}
});
}
}
};
</script>
更多推荐
已为社区贡献3条内容
所有评论(0)