好了这事一个非常艰巨的任务  解释以下的全部代码

  1. <template>
  2. <div class="hello">
  3. <p style="color:gray">
  4. 提示:在vscode terminal中使用npm run server启动服务,否则是看不到效果的
  5. </p>
  6. <!-- <el-button @click="check">点击以测试接口</el-button>
  7. <el-row>
  8. <el-select v-model="method">
  9. <el-option
  10. v-for="(m, key) in methods"
  11. :key="key"
  12. :label="m + '(' + key + ')'"
  13. :value="key"
  14. ></el-option>
  15. </el-select>
  16. </el-row>
  17. <el-row style="width:40%;">
  18. 用户名:<el-input v-model="id"></el-input>
  19.  
  20. 密码:<el-input v-model="password"></el-input>
  21.  
  22. 年龄:<el-input v-model="age"></el-input>
  23.  
  24. 性别:<el-input v-model="sexual"></el-input>
  25. </el-row> -->
  26. <h1 style="text-align:center">
  27. 用户操作表
  28. </h1>
  29. <pre>
  30. {{ result }}
  31. </pre>
  32. <!---测试案例-->
  33. <el-row>
  34. <el-button @click="addUser">添加用户</el-button>
  35. </el-row>
  36. <el-table :data="tableData" style="width: 100%">
  37. <el-table-column prop="id" label="用户名" width="180"> </el-table-column>
  38. <el-table-column prop="password" label="用户密码" width="180">
  39. </el-table-column>
  40. <el-table-column prop="age" label="年龄"> </el-table-column>
  41. <el-table-column prop="sexual" label="性别">
  42. <template slot-scope="scope">
  43. {{ scope.row.sexual ? "女" : "男" }}
  44. </template>
  45. </el-table-column>
  46. <el-table-column prop="age" label="年龄">
  47. <template slot-scope="scope">
  48. <el-button @click="editUser(scope.row)" type="text" size="small"
  49. >编辑</el-button
  50. >
  51. <el-button @click="removeUser(scope.row)" type="text" size="small"
  52. >删除</el-button
  53. >
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <el-dialog :visible.sync="showDialog">
  58. <el-row style="width:40%;">

  59. 用户名:<el-input v-model="id" :disabled="mode == 'update'"></el-input>
  60.  
  61. 密码:<el-input v-model="password"></el-input>
  62.  
  63. 年龄:<el-input-number v-model="age"></el-input-number>
  64.  
  65. 性别:<el-select v-model="sexual">
  66. <el-option label="男" :value="0"></el-option>
  67. <el-option label="女" :value="1"></el-option>
  68. </el-select>
  69. </el-row>
  70. <div slot="footer">
  71. <el-button @click="showDialog = false">取 消</el-button>
  72. <el-button type="primary" @click="apply(mode)">{{
  73. mode == "add" ? "创建" : "编辑"
  74. }}</el-button>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </template>

    下面是脚本了
  79. <script>
  80. export default {
  81. name: "HelloWorld",
  82. mounted() {
  83. this.refreshTable();
  84. },
  85. data() {
  86. return {
  87. showDialog: false,
  88. mode: "add",
  89. tableData: [],
  90. methods: {
  91. save: "保存用户信息",
  92. update: "修改用户信息",
  93. check: "验证密码",
  94. delete: "删除用户",
  95. add: "添加用户",
  96. get: "获取用户信息"
  97. },
  98. method: "check",
  99. result: "",
  100. age: "",
  101. sexual: "",
  102. id: "",
  103. password: ""
  104. };
  105. },
  106. methods: {
  107. apply(mode) {
  108. this.send(
  109. mode,
  110. {
  111. id: this.id,
  112. password: this.password,
  113. sexual: this.sexual,
  114. age: this.age
  115. },
  116. () => {
  117. this.refreshTable();
  118. this.showDialog = false;
  119. }
  120. );
  121. },
  122. addUser() {
  123. this.showDialog = true;
  124. this.mode = "add";
  125. ["id", "sexual", "age", "password"].forEach(item => {
  126. this[item] = undefined;
  127. });
  128. },
  129. editUser(source) {
  130. this.showDialog = true;
  131. this.mode = "update";
  132. ["id", "sexual", "age", "password"].forEach(item => {
  133. this[item] = source[item];
  134. });
  135. },
  136. removeUser(user) {
  137. this.send("delete", user, () => {
  138. this.refreshTable();
  139. });
  140. },
  141. send(method, option, callback) {
  142. this.result = "";
  143. this.$axios.post("/user/" + method, option).then(res => {
  144. let result = res.data;
  145. if (result.status == -1) {
  146. alert(result.msg);
  147. return;
  148. }
  149. callback(result.data && JSON.parse(JSON.stringify(result.data)));
  150. });
  151. },
  152. refreshTable() {
  153. this.send("get", {}, data => {
  154. this.tableData = data;
  155. });
  156. },
  157. check() {
  158. this.result = "";
  159. this.$axios
  160. .post("/user/" + this.method, {
  161. id: this.id,
  162. age: this.age,
  163. password: this.password,
  164. sexual: this.sexual
  165. })
  166. .then(res => {
  167. console.log("res=>", res);
  168. this.result = res.data;
  169. });
  170. }
  171. }
  172. };
  173. </script>

第十三篇:axios网络通信的更多相关文章

  1. 解剖SQLSERVER 第十三篇 Integers在行压缩和页压缩里的存储格式揭秘(译)

    解剖SQLSERVER 第十三篇    Integers在行压缩和页压缩里的存储格式揭秘(译) http://improve.dk/the-anatomy-of-row-amp-page-compre ...

  2. 第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  3. Python之路【第十三篇】:jQuery -暂无内容-待更新

    Python之路[第十三篇]:jQuery -暂无内容-待更新

  4. Python开发【第二十三篇】:持续更新中...

    Python开发[第二十三篇]:持续更新中...

  5. Python开发【第十三篇】:jQuery(二)

    http://www.bubuko.com/infodetail-1438296.html 处理完毕需要整理贴进来 Python之路[第十三篇]jQuery案例-Form表单&插件及扩展   ...

  6. Python开发【第十三篇】:jQuery--无内容点击-不进去(一)

    Python开发[第十三篇]:jQuery--无内容点击-不进去(一)

  7. 十三篇系列:king转折点,wooga瓶颈,supercell营收结构

    转自:http://gamerboom.com/archives/95125 十三篇系列:king的历史转折点,wooga的瓶颈,supercell的营收结构 第一篇 这句话In other word ...

  8. 【译】第十三篇 Integration Services:SSIS变量

    本篇文章是Integration Services系列的第十三篇,详细内容请参考原文. 简介在前一篇我们结合了之前所学的冒泡.日志记录.父子模式创建一个自定义的SSIS包日志记录模式.在这一篇,我们将 ...

  9. 跟我学SpringCloud | 第十三篇:Spring Cloud Gateway服务化和过滤器

    SpringCloud系列教程 | 第十三篇:Spring Cloud Gateway服务化和过滤器 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich. ...

随机推荐

  1. Ubuntu远程桌面助手(URDC)

    目前自动驾驶域控制器项目中使用了英伟达的Orin芯片+Ubuntu20.04系统.域控属于典型的Headless设备,开发调试时需要连接显示器(HDMI/DP).鼠标和键盘,或者使用NoMachine ...

  2. 领导:谁再用redis过期监听实现关闭订单,立马滚蛋!

    日前拜读阿牛老师的大作 领导:谁再用定时任务实现关闭订单,立马滚蛋! 发现其方案有若干瑕疵,特此抛砖引玉讨论一二. 在电商.支付等领域,往往会有这样的场景,用户下单后放弃支付了,那这笔订单会在指定的时 ...

  3. 新上线!3D单模型轻量化硬核升级,G级数据轻松拿捏!

    "3D模型体量过大.面数过多.传输展示困难",用户面对这样的3D数据,一定不由得皱起眉头.更便捷.快速处理三维数据,是每个3D用户对高效工作的向往. 在老子云最新上线的单模型轻量化 ...

  4. 3D可视化在化工领域的应用及案例分享

    2020年,中办.国办印发的<关于全面加强危险化学品安全生产工作的意见>中重点提出应加快"推进化工园区安全生产信息化.智能化平台建设,实现对园区内企业.重点场所.重大危险源.基础 ...

  5. SpringCloudAlibaba学习(解决SpringBoot初始化以及Nginx启动出错问题)

    微服务强调每个服务都是单独的数据库 在不使用微服务的情况下可以采用分布式架构,通过Template来调用远程的Rest接口 但这种方式维护起来很麻烦,而且有很多弊端. 一.环境搭建 1.首先搭建Spr ...

  6. vue封装手机验证码

    // 获取验证码 let endMsRes = new Date().getTime() + 45000; localStorage.setItem("myEndTime", JS ...

  7. bat-Office激活命令

    激活命令 cd C:\Program Files\Microsoft Office\Office16 //然后目录对的话,该目录下面应该有个 OSPP.VBS cscript ospp.vbs /ds ...

  8. Python自动化办公:27行代码实现将多个Excel表格内容批量汇总合并到一个表格

    序言 (https://jq.qq.com/?_wv=1027&k=GmeRhIX0) 老板最近越来越过分了,快下班了发给我几百个表格让我把内容合并到一个表格内去.还好我会Python,分分钟 ...

  9. 毕设之Python爬取天气数据及可视化分析

    写在前面的一些P话:(https://jq.qq.com/?_wv=1027&k=RFkfeU8j) 天气预报我们每天都会关注,我们可以根据未来的天气增减衣物.安排出行,每天的气温.风速风向. ...

  10. python报错合集

    哈喽,大家好呀 我又来啦,今天让我们来看看python中有哪些常见的异常报错吧 说到python中的报错,我们总是脑壳疼现在我们要学会去认识报错的类型 这样子,在我们出现报错的时候就可以知道报错的原因 ...