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

<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网络通信的更多相关文章

  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. 【Spring】AOP实现原理(一):AOP基础知识

    AOP相关概念 在学习AOP实现原理之前,先了解下AOP相关基础知识. AOP面向切面编程,它可以通过预编译方式或者基于动态代理对我们编写的代码进行拦截(也叫增强处理),在方法执行前后可以做一些操作, ...

  2. React与Koa一起打造一个功能丰富的全栈个人博客(业务篇)

    前言 豆哥的个人博客又改版了,本版主要技术栈是前台用的React,后台用的Koa.博客改版的初衷是自己可以练练React(公司的项目部分要用React,我也没法啊,再说早晚得学).本文主要介绍博客的业 ...

  3. Linux shell 2>&1的意思

    在脚本里经常看到 ./xxx.sh > /dev/null 2>&1 ./xxx.sh > log.file 2>&1 在shell中输入输出都有对应的文件描述 ...

  4. SAP APO-数据集市,信息多维数据集和Dp

    在SAP Advanced Planning and Optimization中,每个数据集市都包含InfoCube,这些InfoCube存储实际数据和较早的计划数据. 在诸如SAP BW之类的数据仓 ...

  5. UiPath培训教程

    匠厂出品,必属精品   Uipath中文社区qq交流群:465630324 uipath中文交流社区:https://uipathbbs.comRPA之家qq群:465620839 第一课--UiPa ...

  6. 原生实现.NET5.0+ 自定义日志

    一.定义一个静态类 声明一个 ReaderWriterLockSlim 对象 用于并发控制 1 /// <summary> 2 /// IO锁 3 /// </summary> ...

  7. 【前端面试】(四)JavaScript var let const的区别

    视频链接: JavaScript var let const的区别 - Web前端工程师面试题讲解 参考链接: JavaScript 变量 JavaScript Let JavaScript Cons ...

  8. Java去除字符串中 除数字和逗号以外的符号

    例: public static void main(String[] args) { // 去除字符串中 除数字和逗号以外的符号 String str = "_1066,_1068,_10 ...

  9. 模拟HashMap冲突

    最近看HashMap的源码,其中相同下标容易产生hash冲突,但是调试需要发生hash冲突,本文模拟hash冲突. hash冲突原理 HashMap冲突是key首先调用hash()方法: static ...

  10. GitHub中Fork来的仓库如何进行双向更新

    一.做点贡献 想对别人的某个仓库"做点贡献"怎么办? 1. Fork该仓库 首先Fork该仓库,本文以git-learn这个仓库为例 这样自己的账号下就会出现这样一个仓库 2. C ...