1,565
社区成员
发帖
与我相关
我的任务
分享
EdgerOS
后端程序是基于 RESTful
风格的 Web
应用程序框架构建的, 支持 GET
, POST
, DELETE
, HEAD
, PUT
等 RESTful
各种请求方法。
前端技术众多,开发者可根据自己意愿安装相应的 HTTP
插件,本教程目前采用的是 Vue
的 Axios
插件,通过 <script>
标签引入静态 js
文件, 如下:
<!--引入vue.js-->
<script src="./vue/vue.min.js"></script>
<!--引入vue.js axios插件-->
<script src="./vue/axios.min.js"></script>
下面程序是一个查询用户信息列表的简单例子:
getUsers: function () {
const auth = {
'edger-token': this.token,
'edger-srand': this.srand
};
axios
.get('/api/user', {}, {headers: auth})
.then(res =>{
console.log(res.body);
})
.catch(function (error) {
console.log(error);
});
}
后端处理 get
请求:
router.get('/api/user', function(req, res) {
res.json(
{
result: true,
message: 'success',
data: users
}
);
});
前端通过 post
请求,提交用户填写的个人信息:
addUser: function () {
const auth = {
'edger-token': this.token,
'edger-srand': this.srand
};
axios
.post('/api/user', { name: this.name, phone: this.phone }, {headers: auth})
.then(res => {
console.log(res.body);
})
.catch(function (error) {
console.log(error);
});
}
后端处理 post
请求:
router.post('/api/user', function(req, res) {
// 数据库或其他操作
res.json({
result: true,
message: 'success'
});
});