【技术实战】Vue技术实战【二】
需求实战一
效果展示

代码展示
<template>
<div>
<a-table :dataSource="dataSource" :columns="columns" />
</div>
</template>
<script setup lang="ts">
const dataSource= ref([
{
key: '1',
name: '胡彦斌',
age: 32,
address: '西湖区湖底公园1号',
},
{
key: '2',
name: '胡彦祖',
age: 42,
address: '西湖区湖底公园1号',
},
])
const columns=ref([
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '年龄',
dataIndex: 'age',
key: 'age',
},
{
title: '住址',
dataIndex: 'address',
key: 'address',
},
])
</script>
代码解读
需求实战二
效果展示

代码展示
<template>
<div>
<a-button type="primary" @click="addRow">新增</a-button>
<br>
<br>
<br>
<a-table :dataSource="dataSource" :columns="columns" bordered>
<template #operation="{ record }">
<a-button type="primary" @click="editRow(record)">编辑</a-button>
 
 
 
<a-button type="danger" @click="deleteRow(record)">删除</a-button>
</template>
<template #title>
<div style="text-align: center;">个人信息表格</div>
</template>
</a-table>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const dataSource = ref([
{
key: '1',
name: '张三',
age: '32',
address: '天安门广场',
},
{
key: '2',
name: '李四',
age: '42',
address: '紫禁城',
},
])
const columns = ref([
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '年龄',
dataIndex: 'age',
key: 'age',
},
{
title: '住址',
dataIndex: 'address',
key: 'address',
},
{
title: '操作',
dataIndex: 'operation',
slots: { customRender: 'operation' },
},
])
const editRow = (record: any) => {
const index = dataSource.value.findIndex((item: any) => item.key === record.key);
if (index !== -1) {
const newName = prompt('Enter new name:');
const newAge = prompt('Enter new age:');
const newAddress = prompt('Enter new address:');
if (newName && newAge && newAddress) {
dataSource.value[index].name = newName;
dataSource.value[index].age = newAge;
dataSource.value[index].address = newAddress;
}
}
}
const deleteRow = (record: any) => {
const index = dataSource.value.findIndex((item) => item.key === record.key)
if (index !== -1) {
dataSource.value.splice(index, 1)
}
}
const addRow = () => {
const newName = prompt('Enter name:');
const newAge = prompt('Enter age:');
const newAddress = prompt('Enter address:');
if (newName && newAge && newAddress) {
const newKey = String(dataSource.value.length + 1);
dataSource.value.push({
key: newKey,
name: newName,
age: newAge,
address: newAddress,
});
}
}
</script>
代码解读
需求实战三
效果展示

代码展示
<template>
<ARow>
<a-button type="primary" @click="handleAdd" >新增</a-button>
</ARow>
<br>
<br>
<br>
<ARow>
<a-table :columns="columns" :data-source="dataSource" bordered>
<template v-for="col in ['name', 'age', 'address']" #[col]="{ text, record }" :key="col">
<div>
<a-input
v-if="editableData[record.key]"
v-model:value="editableData[record.key][col]"
style="margin: -5px 0"
/>
<template v-else>
{{ text }}
</template>
</div>
</template>
<template #operation="{ record }">
<div class="editable-row-operations">
<span v-if="editableData[record.key]">
<div style="display: flex; justify-content: space-between;">
<a-button type="primary" @click="save(record.key)">保存</a-button>
   
<a-button type="danger" @click="cancel(record.key)">
取消
</a-button>
</div>
</span>
<span v-else>
<div style="display: flex; justify-content: space-between;">
<a-button type="primary" @click="edit(record.key)">编辑</a-button>
   
<a-button type="danger" @click="onDelete(record.key)">删除</a-button>
</div>
</span>
</div>
</template>
</a-table>
</ARow>
</template>
<script setup lang="ts">
import { cloneDeep } from 'lodash-es';
import { reactive, UnwrapRef } from 'vue';
const columns = [
{
title: 'name',
dataIndex: 'name',
slots: { customRender: 'name' },
},
{
title: 'age',
dataIndex: 'age',
slots: { customRender: 'age' },
},
{
title: 'address',
dataIndex: 'address',
slots: { customRender: 'address' },
},
{
title: 'operation',
dataIndex: 'operation',
slots: { customRender: 'operation' },
},
];
interface DataItem {
key: string;
name: string;
age: number;
address: string;
}
const data: DataItem[] = [];
for (let i = 0; i < 100; i++) {
data.push({
key: i.toString(),
name: `Edrward ${i}`,
age: 32,
address: `London Park no. ${i}`,
});
}
const handleAdd = () => {
const newData = {
key: `${count.value}`,
name: `Edward King ${count.value}`,
age: 32,
address: `London, Park Lane no. ${count.value}`,
};
dataSource.value.push(newData);
};
const count = computed(() => dataSource.value.length + 1);
const dataSource = ref(data);
const editableData: UnwrapRef<Record<string, DataItem>> = reactive({});
const edit = (key: string) => {
editableData[key] = cloneDeep(dataSource.value.filter(item => key === item.key)[0]);
};
const save = (key: string) => {
Object.assign(dataSource.value.filter(item => key === item.key)[0], editableData[key]);
delete editableData[key];
};
const cancel = (key: string) => {
delete editableData[key];
};
const onDelete = (key: string) => {
dataSource.value = dataSource.value.filter(item => item.key !== key);
};
</script>
代码解读
【技术实战】Vue技术实战【二】的更多相关文章
- Vue应用框架整合与实战--Vue技术生态圈篇
实用框架以及工具 UI组件 开发框架 实用库 服务端 辅助工具 应用实例 Demo示例 UI组件 Element-UI ★13489 - 饿了么出品的Vue2的web UI工具套件 Vux ★8133 ...
- 深度解析SDN——利益、战略、技术、实践(实战派专家力作,业内众多专家推荐)
深度解析SDN——利益.战略.技术.实践(实战派专家力作,业内众多专家推荐) 张卫峰 编 ISBN 978-7-121-21821-7 2013年11月出版 定价:59.00元 232页 16开 ...
- 超级干货:动态防御WAF技术原理及编程实战!
本文带给大家的内容是动态防御WAF的技术原理及编程实战. 将通过介绍ShareWAF的核心技术点,向大家展示动态防御的优势.实现思路,并以编程实战的方式向大家展示如何在WAF产品开发过程中应用动态防御 ...
- 简读《ASP.NET Core技术内幕与项目实战》之3:配置
特别说明:1.本系列内容主要基于杨中科老师的书籍<ASP.NET Core技术内幕与项目实战>及配套的B站视频视频教程,同时会增加极少部分的小知识点2.本系列教程主要目的是提炼知识点,追求 ...
- 快读《ASP.NET Core技术内幕与项目实战》EFCore2.5:集合查询原理揭秘(IQueryable和IEnumerable)
本节内容,涉及4.6(P116-P130).主要NuGet包:如前述章节 一.LINQ和EFCore的集合查询扩展方法的区别 1.LINQ和EFCore中的集合查询扩展方法,虽然命名和使用完全一样,都 ...
- 快读《ASP.NET Core技术内幕与项目实战》WebApi3.1:WebApi最佳实践
本节内容,涉及到6.1-6.6(P155-182),以WebApi说明为主.主要NuGet包:无 一.创建WebApi的最佳实践,综合了RPC和Restful两种风格的特点 1 //定义Person类 ...
- 《ASP.NET Core技术内幕与项目实战》精简集-目录
本系列是杨中科2022年最新作品<ASP.NET Core技术内幕与项目实战>及B站配套视频(强插点赞)的精简集,是一个读书笔记.总结和提炼了主要知识点,遵守代码优先原则,以利于快速复习和 ...
- 躬身入局,干货分享,2023年春招后端技术岗(Python)面试实战教程,Offer今始为君发
早春二月,研发倍忙,杂花生树,群鸥竟飞.为什么?因为春季招聘,无论是应届生,还是职场老鸟,都在摩拳擦掌,秣马厉兵,准备在面试场上一较身手,既分高下,也决Offer,本次我们打响春招第一炮,躬身入局,让 ...
- 基于TC技术的网络流量控制实战
本文转载在:http://server.it168.com/a2010/0426/878/000000878406.shtml 基于TC技术的网络流量控制实战 650) this.width=650; ...
- 从开发一款基于Vue技术栈的全栈热重载生产环境脚手架,我学到了什么
浏览文章前 这一期,我分享给大家三点看源码的小技巧,这也是从别的大佬那总结的. 被反复使用的代码 这样的代码是一个软件的重点函数,一个大神的写法有很多精华值得学习. 穿越时间的代码 如果一段代码10年 ...
随机推荐
- 一个可用于生产项目 基于 .NET 6 自研ORM
Fast Framework 作者 Mr-zhong 代码改变世界.... 一.前言 Fast Framework 基于NET6.0 封装的轻量级 ORM 框架 支持多种数据库 SqlServer O ...
- 30-externals(拒绝某些包被打包进来)
const { resolve } = require('path') const HtmlWebpackPlugin = require('html-webpack-plugin') module. ...
- Win Pycharm + Appium + 真机 实现APP自动化
前言: 测试的APP:亿通行 手机型号:OPPO 系统:安卓10 一.安装Python3.x 1.直接登录Python官网https://www.python.org/,下载最新版本即可 2.安装Py ...
- 【Docker】安装及部署
一.Ubuntu使用apt安装Docker 官方安装文档:https://docs.docker.com/engine/install/ubuntu/ 1.准备安装环境 [root@Docker-Ub ...
- Maven工程开发
Maven工程开发 编写pom.xml配置文件 <properties></properties>定义项目的基本信息 groupId 反向域名,定义项目组名 artifactI ...
- 苦苦搞了半个通宵才搞定的直接使用Sliverlight将文件PUT到阿里云OSS
为了公司的项目,小的我各种折腾啊,不过高兴的是实现了Silverlight直接提交至阿里云OSS的文件上传,文件上传再也不用通过服务器中转了. 研究SDK发现还有个Node-oss.js,但还没进行测 ...
- 解决pod健康检查问题
解决pod健康检查问题 引自:Solving the mystery of pods health checks failures in Kubernetes.原文中的某些描述并不清晰,本文作了调整. ...
- Vulhub activewq_漏洞复现——源码分析
Vulhub activewq_漏洞复现--源码分析 漏洞简介 Apache ActiveMQ是由美国阿帕奇(Apache)软件基金会开发的开源消息中间件,支持Java消息服务.集群.Spring框架 ...
- Mysql列转行, group_concat的使用
开始业务的查询的时候碰到一个sql的查询语句问题,主要是 group_concat 之前没用过,现在记录一下怎么用 group_concat 用法, 可以将相同的行组合起来 group_concat( ...
- HTB靶场之-inject
准备: 攻击机:虚拟机kali. 靶机:Inject,htb网站:https://www.hackthebox.com/,靶机地址:https://app.hackthebox.com/machine ...