一、关于for-in校验表单
代码如下(示例):
onsubmit2(){
//itemObj 是 object 对象
itemObj:{
title:"",
posttime:new Date().getTime()/1000,
classify:"",
author:"",
content:""
}
//item 代表itemObj中的每一个属性
for(var item in this.itemObj){
console.log(this.itemObj[item])
if(this.itemObj[item]==''){
alert("请按要求填写");
return
}
}
axios({
url:"https://ku.qingnian8.com/dataApi/blog/addBlog.php",
params:this.itemObj
}).then(res=>{
if(res.data.code==200){
console.log(res)
alert("发布成功");
}
})
}