premise
You need to have basic node knowledge before watching this article
Start showing
- Because the explanation is too complicated, this article uses code to demonstrate
- General idea
- A page request interface, passing parameters
- The interface receives the parameter and executes the specified function to call the database
- The specified function receives the parameter and calls the database according to the parameter
- Recall the completed database and return the retrieved result to the interface
- The interface receives the parameters and executes the follow-up procedure (when accepting success, what is returned when accepting failure)
- The page requesting the interface receives the data returned by the interface
- Determine what parameters are returned and what function to perform based on the parameters
Code display
transfer
this.$store.dispatch("login",this)
To interface
const actions = {
async login(context,vm){
const {data}= await axios.post("/ele/login",vm.adminForm) //post请求
if(data.ok ===1){
context.commit("CHANGE_USERNAME",vm.adminForm.adminName)
}else{
vm.$message.error(data.msg)
}
}
};
interface
app.post("/login",(req,res)=>{ //登录
db.findOne("adminList",{ //调用函数
adminName,
adminWord:md5(adminWord+"(*^(*&^(*&)")
},function(err,info){
if(err) tools.json(res);
else{
if(info){
tools.json(res,1,"登陆成功");
}else{
tools.json(res,-1,"账号或密码错误");
}
}
})
});
To the database
findOne(collName,whereObj,cb){
_connect(db=>{
db.collection(collName).findOne(whereObj,cb);
})
},
Do n’t copy my code, just for reference, the code ca n’t run except the interface