第十三篇:axios网络通信
好了这事一个非常艰巨的任务 解释以下的全部代码
- <template>
- <div class="hello">
- <p style="color:gray">
- 提示:在vscode terminal中使用npm run server启动服务,否则是看不到效果的
- </p>
- <!-- <el-button @click="check">点击以测试接口</el-button>
- <el-row>
- <el-select v-model="method">
- <el-option
- v-for="(m, key) in methods"
- :key="key"
- :label="m + '(' + key + ')'"
- :value="key"
- ></el-option>
- </el-select>
- </el-row>
- <el-row style="width:40%;">
- 用户名:<el-input v-model="id"></el-input>
- 密码:<el-input v-model="password"></el-input>
- 年龄:<el-input v-model="age"></el-input>
- 性别:<el-input v-model="sexual"></el-input>
- </el-row> -->
- <h1 style="text-align:center">
- 用户操作表
- </h1>
- <pre>
- {{ result }}
- </pre>
- <!---测试案例-->
- <el-row>
- <el-button @click="addUser">添加用户</el-button>
- </el-row>
- <el-table :data="tableData" style="width: 100%">
- <el-table-column prop="id" label="用户名" width="180"> </el-table-column>
- <el-table-column prop="password" label="用户密码" width="180">
- </el-table-column>
- <el-table-column prop="age" label="年龄"> </el-table-column>
- <el-table-column prop="sexual" label="性别">
- <template slot-scope="scope">
- {{ scope.row.sexual ? "女" : "男" }}
- </template>
- </el-table-column>
- <el-table-column prop="age" label="年龄">
- <template slot-scope="scope">
- <el-button @click="editUser(scope.row)" type="text" size="small"
- >编辑</el-button
- >
- <el-button @click="removeUser(scope.row)" type="text" size="small"
- >删除</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <el-dialog :visible.sync="showDialog">
- <el-row style="width:40%;">
- 用户名:<el-input v-model="id" :disabled="mode == 'update'"></el-input>
- 密码:<el-input v-model="password"></el-input>
- 年龄:<el-input-number v-model="age"></el-input-number>
- 性别:<el-select v-model="sexual">
- <el-option label="男" :value="0"></el-option>
- <el-option label="女" :value="1"></el-option>
- </el-select>
- </el-row>
- <div slot="footer">
- <el-button @click="showDialog = false">取 消</el-button>
- <el-button type="primary" @click="apply(mode)">{{
- mode == "add" ? "创建" : "编辑"
- }}</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
下面是脚本了- <script>
- export default {
- name: "HelloWorld",
- mounted() {
- this.refreshTable();
- },
- data() {
- return {
- showDialog: false,
- mode: "add",
- tableData: [],
- methods: {
- save: "保存用户信息",
- update: "修改用户信息",
- check: "验证密码",
- delete: "删除用户",
- add: "添加用户",
- get: "获取用户信息"
- },
- method: "check",
- result: "",
- age: "",
- sexual: "",
- id: "",
- password: ""
- };
- },
- methods: {
- apply(mode) {
- this.send(
- mode,
- {
- id: this.id,
- password: this.password,
- sexual: this.sexual,
- age: this.age
- },
- () => {
- this.refreshTable();
- this.showDialog = false;
- }
- );
- },
- addUser() {
- this.showDialog = true;
- this.mode = "add";
- ["id", "sexual", "age", "password"].forEach(item => {
- this[item] = undefined;
- });
- },
- editUser(source) {
- this.showDialog = true;
- this.mode = "update";
- ["id", "sexual", "age", "password"].forEach(item => {
- this[item] = source[item];
- });
- },
- removeUser(user) {
- this.send("delete", user, () => {
- this.refreshTable();
- });
- },
- send(method, option, callback) {
- this.result = "";
- this.$axios.post("/user/" + method, option).then(res => {
- let result = res.data;
- if (result.status == -1) {
- alert(result.msg);
- return;
- }
- callback(result.data && JSON.parse(JSON.stringify(result.data)));
- });
- },
- refreshTable() {
- this.send("get", {}, data => {
- this.tableData = data;
- });
- },
- check() {
- this.result = "";
- this.$axios
- .post("/user/" + this.method, {
- id: this.id,
- age: this.age,
- password: this.password,
- sexual: this.sexual
- })
- .then(res => {
- console.log("res=>", res);
- this.result = res.data;
- });
- }
- }
- };
- </script>
第十三篇:axios网络通信的更多相关文章
- 解剖SQLSERVER 第十三篇 Integers在行压缩和页压缩里的存储格式揭秘(译)
解剖SQLSERVER 第十三篇 Integers在行压缩和页压缩里的存储格式揭秘(译) http://improve.dk/the-anatomy-of-row-amp-page-compre ...
- 第十三篇 Integration Services:SSIS变量
本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...
- Python之路【第十三篇】:jQuery -暂无内容-待更新
Python之路[第十三篇]:jQuery -暂无内容-待更新
- Python开发【第二十三篇】:持续更新中...
Python开发[第二十三篇]:持续更新中...
- Python开发【第十三篇】:jQuery(二)
http://www.bubuko.com/infodetail-1438296.html 处理完毕需要整理贴进来 Python之路[第十三篇]jQuery案例-Form表单&插件及扩展 ...
- Python开发【第十三篇】:jQuery--无内容点击-不进去(一)
Python开发[第十三篇]:jQuery--无内容点击-不进去(一)
- 十三篇系列:king转折点,wooga瓶颈,supercell营收结构
转自:http://gamerboom.com/archives/95125 十三篇系列:king的历史转折点,wooga的瓶颈,supercell的营收结构 第一篇 这句话In other word ...
- 【译】第十三篇 Integration Services:SSIS变量
本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...
- 跟我学SpringCloud | 第十三篇:Spring Cloud Gateway服务化和过滤器
SpringCloud系列教程 | 第十三篇:Spring Cloud Gateway服务化和过滤器 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich. ...
随机推荐
- Ubuntu远程桌面助手(URDC)
目前自动驾驶域控制器项目中使用了英伟达的Orin芯片+Ubuntu20.04系统.域控属于典型的Headless设备,开发调试时需要连接显示器(HDMI/DP).鼠标和键盘,或者使用NoMachine ...
- 领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
日前拜读阿牛老师的大作 领导:谁再用定时任务实现关闭订单,立马滚蛋! 发现其方案有若干瑕疵,特此抛砖引玉讨论一二. 在电商.支付等领域,往往会有这样的场景,用户下单后放弃支付了,那这笔订单会在指定的时 ...
- 新上线!3D单模型轻量化硬核升级,G级数据轻松拿捏!
"3D模型体量过大.面数过多.传输展示困难",用户面对这样的3D数据,一定不由得皱起眉头.更便捷.快速处理三维数据,是每个3D用户对高效工作的向往. 在老子云最新上线的单模型轻量化 ...
- 3D可视化在化工领域的应用及案例分享
2020年,中办.国办印发的<关于全面加强危险化学品安全生产工作的意见>中重点提出应加快"推进化工园区安全生产信息化.智能化平台建设,实现对园区内企业.重点场所.重大危险源.基础 ...
- SpringCloudAlibaba学习(解决SpringBoot初始化以及Nginx启动出错问题)
微服务强调每个服务都是单独的数据库 在不使用微服务的情况下可以采用分布式架构,通过Template来调用远程的Rest接口 但这种方式维护起来很麻烦,而且有很多弊端. 一.环境搭建 1.首先搭建Spr ...
- vue封装手机验证码
// 获取验证码 let endMsRes = new Date().getTime() + 45000; localStorage.setItem("myEndTime", JS ...
- bat-Office激活命令
激活命令 cd C:\Program Files\Microsoft Office\Office16 //然后目录对的话,该目录下面应该有个 OSPP.VBS cscript ospp.vbs /ds ...
- Python自动化办公:27行代码实现将多个Excel表格内容批量汇总合并到一个表格
序言 (https://jq.qq.com/?_wv=1027&k=GmeRhIX0) 老板最近越来越过分了,快下班了发给我几百个表格让我把内容合并到一个表格内去.还好我会Python,分分钟 ...
- 毕设之Python爬取天气数据及可视化分析
写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...
- python报错合集
哈喽,大家好呀 我又来啦,今天让我们来看看python中有哪些常见的异常报错吧 说到python中的报错,我们总是脑壳疼现在我们要学会去认识报错的类型 这样子,在我们出现报错的时候就可以知道报错的原因 ...