vuejs项目开发中,如何利用form-data发送请求,下面web建站小编给大家简单介绍一下具体实例!
安装脚手架:
npm install axios
示列代码:
<template>
<div>
<form>
<input type="text" v-model="name" />
<input type="file" ref="file" />
<button @click.prevent="submitForm">Submit</button>
</form>
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'FormDataExample',
data() {
return {
name: '',
};
},
methods: {
async submitForm() {
const formData = new FormData();
formData.append('name', this.name);
formData.append('file', this.$refs.file.files[0]);
try {
const response = await axios.post('/api/submit-form', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
console.log(response);
} catch (error) {
console.error(error);
}
},
},
};
</script>
element-ui时间选择器el-date-picker默认当前时间至7天之前时间
vue实现表格的编辑,包括选择,合并,拆分,删除行/列,添加行/列
Motion for Vue:一个轻量级且功能强大的Vue3动画库
上面是“vuejs如何利用form-data发送请求”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4159.html
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

什么是生成对抗网络(GAN)?它的主要特征是什么?
html5如何3D立方体旋转特效 












