【技术实战】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年 ...
随机推荐
- C# 几种获取电脑内存、CPU信息的方案
计数器.WMI 获取设备的内存信息,如系统可用运行内存: 1 public static async Task<double> GetMemoryAvailableAsync(FileSi ...
- [Pytorch框架] 1.7 数据并行
数据并行(选读) Authors: Sung Kim and Jenny Kang 在这个教程里,我们将学习如何使用 DataParallel 来使用多GPU. PyTorch非常容易就可以使用多GP ...
- 一天吃透Redis面试八股文
Redis连环40问,绝对够全! Redis是什么? Redis(Remote Dictionary Server)是一个使用 C 语言编写的,高性能非关系型的键值对数据库.与传统数据库不同的是,Re ...
- Prisim Sample 7 Modules App.Config
在项目中添加模块化文件.模块文件怎样在主项目中注册.本例 说明方式一,使用了App.config文件. 其中: <?xml version="1.0" encoding=&q ...
- ai问答:vue3+pinia+WebSocket 封装断线重连(实战)
把socket实例 挂载到全局 为方便梳理,请忽略typescript # main.ts import {createApp} from 'vue' import App from './App.v ...
- nuxt下运行项目时内存溢出(out of memory)的一种情况
话不多说直接上代码: 如图,点红点的三行引入了一个组件,内容是同意注册协议的弹窗.但是在run dev的时候提示说内存溢出了(out of memory)...经过多方排查,定位到这个组件,警察叔叔就 ...
- 解决v-html渲染HTML标签展示信息有误问题
后端返回的数据内容为: // html反转义 HTMLDecode(text) { var reg = /<[^>]+>/g; if (reg.test(text)) { retur ...
- GRPC与 ProtoBuf 的理解与总结
转载请注明出处: 1.GRPC 官网:https://www.grpc.io/ gRPC 官方文档中文版:http://doc.oschina.net/grpc RPC 框架的目标就是让远程服务调用更 ...
- SpringMVC使用注解开发
1.编写web.xml(模板代码) 2.导入springmvc的context和mvc两个依赖,通过context标签可以自动扫描识别包"com.lian.controller"下 ...
- web自动化06-键盘操作
键盘操作 1.说明: 1). 模拟键盘上一些按键或者组合键的输入 如:Ctrl+C .Ctrl+V: 2). Selenium中把键盘的按键都封装在Keys类中 2. Keys类 导包:from se ...