只是在vue的学习过程中,用fetch简单的访问一下,本地文件夹
methods:{
async submitFn(){
try{
let form = this.$refs['form1'];
let dataform = new FormData(form);
let res = await fetch('./data/1.php',{
method:'post',
mode: "cors",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body:'a=5&b=2'
});
let data = await res.json();
console.log(data);
}catch(e){
}
}
}
但是总是报错404,找不到路径
php文件内容是copy来的
<?PHP
echo $_POST['a']+$_POST['b'];
?>