vue typescript curd
用typescript 完成了一个页面
import { Component, Prop } from 'vue-property-decorator';
import Vue, { VNode } from 'vue';
import { Form } from 'ant-design-vue';
import api from '@/api/post_category';
@Component({
name: 'PostCategory',
components: {
},
})
class PostCategory extends Vue {
@Prop() public form: any;
private loading = false;
private dataSource = []
private columns = [
{ title: '名称', dataIndex: 'name' },
{ title: '路径', dataIndex: 'code' }
];
private options = [];
private selectedRows = []
public mounted() {
this.loadData()
}
public loadData() {
api.list()
.then(res => {
this.dataSource = Object.assign([], res)
this.options = Object.assign([], res)
}).catch(err => {
this.$notification.error({message: err.message});
})
}
public displayRender(item: any) {
return item.labels[item.labels.length - 1];
}
private handleSave() {
this.form.validateFields((err: any, values: any) => {
if (!err) {
const param = Object.assign({}, values)
if (Array.isArray(values.parentUid)) {
param.parentUid = values.parentUid[values.parentUid.length - 1]
}
api.addPostCategory(param)
.then(() => {
this.loadData()
this.$notification.success({message: '保存成功'})
}).catch((err) => {
this.$notification.error({message: err.message});
});
}
})
}
private handleModify() {
if (this.selectedRows.length !== 1) {
this.$notification.warn({message: '请选择一行数据进行修改'})
return
}
this.form.setFieldsValue(Object.assign({}, this.selectedRows[0]))
}
private handleDelete() {
if (this.selectedRows.length === 0) {
this.$notification.warn({message: '请选择一行数据进行修改'})
return
}
const self = this
this.$confirm({
title: '请确认你要删除这些项目',
cancelText: '取消',
okText: '确认',
onOk() {
const list = self.selectedRows.map(it => it.uid)
api.delete(list)
.then(() => {
self.loadData()
self.$notification.warn({message: '删除成功'})
}).catch(err => this.$notification.error({message: err.message}))
},
onCancel() {},
});
}
private handleAdd() {
this.form.resetFields()
}
private onSelectChange(selectedRowKeys: any, selectedRows: any) {
this.selectedRows = selectedRows
}
public render(): VNode {
const fieldNames = { label: 'name', value: 'uid', children: 'children'}
const scroll = { y: innerHeight - 200 };
const { getFieldDecorator } = this.form;
const rowSelection = {
onChange: this.onSelectChange
}
return (
<a-row gutter={32}>
<a-col span={6}>
<h3>新增分类</h3>
<a-form layout='vertical'>
<a-form-item label='名称' help='名称是它显示在网页上。'>
{getFieldDecorator('name', {rules: [{ required: true, message: '请输入账号' }], validateTrigger: 'blur'})(
<a-input id='name' placeholder='请输入名称'></a-input>
)}
</a-form-item>
<a-form-item label='路径' help='它通常是地址栏里面的路径,它通常都是小写的,只包含字母、数字和连字符。'>
{getFieldDecorator('code')(
<a-input id="code"></a-input>
)}
</a-form-item>
<a-form-item label='父分类'>
{getFieldDecorator('parentUid')(
<a-cascader fieldNames={fieldNames} options={this.options} placeholder='选择父分类'/>
)}
</a-form-item>
<a-form-item label='描述' help='默认情况下描述不显示;一些主题可能会显示这一点。'>
{getFieldDecorator('description')(
<a-textarea id="description"></a-textarea>
)}
</a-form-item>
<a-form-item style='text-align:right' loading={this.loading}>
<a-button type='primary' on-click={this.handleSave}>保存</a-button>
</a-form-item>
</a-form>
</a-col>
<a-col span={18}>
<div class='toolbar'>
<a-button size='small' on-click={this.handleAdd}>新增</a-button>
<a-button type='primary' size='small' on-click={this.handleModify}>修改</a-button>
<a-button type='danger' size='small' on-click={this.handleDelete}>删除</a-button>
</div>
<a-table columns={this.columns} size="small" rowKey="uid" rowSelection={rowSelection} dataSource={this.dataSource} pagination={false} scroll={scroll}></a-table>
</a-col>
</a-row>
);
}
}
export default Form.create({})(PostCategory);
vue typescript curd的更多相关文章
- Vue + TypeScript + ElementUI 封装表头查询组件
前段时间有朋友私信我 Vue + TypeScript 的问题,然后就打算写一篇 Vue + TypeScript 封装组件的文章 正好公司项目中需要封装一个表头查询组件,就拿出来分享一下~ 组件的整 ...
- vue + typescript 项目起手式
https://segmentfault.com/a/1190000011744210 2017-10-27 发布 vue + typescript 项目起手式 javascript vue.js t ...
- Vue+Typescript中在Vue上挂载axios使用时报错
Vue+Typescript中在Vue上挂载axios使用时报错 在vue项目开发过程中,为了方便在各个组件中调用axios,我们通常会在入口文件将axios挂载到vue原型身上,如下: main.t ...
- Vue + TypeScript + Element 搭建简洁时尚的博客网站及踩坑记
前言 本文讲解如何在 Vue 项目中使用 TypeScript 来搭建并开发项目,并在此过程中踩过的坑 . TypeScript 具有类型系统,且是 JavaScript 的超集,TypeScript ...
- 使用Vue-cli3搭建Vue+TypeScript项目
一,创建项目 使用 npm 安装 vue-cli 3 和typescript npm i -g @vue/cli typescript 使用vue create命令快速搭建新项目的脚手架 vue cr ...
- almost最好的Vue + Typescript系列02 项目结构篇
基于vue-cli 3.x,配合typescript的环境构建的新vue项目,跟以前的结构相比,有了一些变化,下面我们来简单的了解一下 基本结构: node_modules: 项目中安装的依赖模块 p ...
- vue+typescript基础练习
环境 win10 node -v 8.9.3 vue-cli 3.4 typescript 3.1.5 编辑器 vscode 目标 使用vuecli工具,建立一个项目,使用typescript.并实现 ...
- Vue+Typescript项目中使用echarts
方案一:推荐 在typescript+Vue的项目中引用echarts,为了加强引用,引入echarts和@types/echarts两个包,一个是工程依赖,一个是声明依赖. npm install ...
- vue+typescript入门学习
最近想要结合vue学习typescript,了解到vue2.5之后开始支持typescript,就像拿vue学习一下,首先要解决的就是环境的搭建,略微麻烦,如果想要自己体验一把,可以参考这篇文章htt ...
随机推荐
- 阶段3 3.SpringMVC·_06.异常处理及拦截器_6 SpringMVC拦截器之拦截器入门代码
创建拦截器 新建包 实现拦截器的接口 接口中没有强制实现里面的方法.jdk1.8的特性.接口中已经实现了方法 这就是相当于实现了这个接口.方法已经全帮你实现过了. 如果想去写新的实现方法.Ctrl+o ...
- EPOLL内核原理极简图文解读(转)
预备知识:内核poll钩子原理内核函数poll_wait把当前进程加入到驱动里自定义的等待队列上 当驱动事件就绪后,就可以在驱动里自定义的等待队列上唤醒调用poll的进程 故poll_wait作用:可 ...
- Mysqlfunc.c
int rc;int db_connection;char *server = "192.168.139.207"; // 数据库的ip地址char *user = "c ...
- 2019.05.30 S4 BUPT BP 客户增强说明
- 看了一圈,发现网上BUPT增强的很少,有的也是做一个字段的页签的增强,我自己花时间研究了一下,在BP增加新的interface 界面按钮. BP页签增强部分就不写了,大家看链接吧 加上如何做出新的 ...
- Strange Java syntax (for me at least)--怪异的Java语法
I've more over 4 years working with Java and today I've seen some piece of code that I thought at fi ...
- Linux 下 Mysql忘记密码重置
1.修改配置文件 /etc/my.cnf 在[mysqld]下 加入skip-grant-tables 2.重启mysql 命令:service mysqld restart 3.等待几分钟后 就可以 ...
- 虚拟环境mkvirtualenv
python虚拟环境mkvirtualenv使用 安装virtualenvwrapper pip install virtualenvwrapper 修改默认虚拟环境目录: 环境变量中新建: ...
- C# Timespan Tostring 时分秒格式
timeSpan.ToString(@"hh\:mm\:ss");
- 如何让JavaScript元素运动起来 ?
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- C语言基础:递归函数,全局(局)变量
#include <stdio.h>int factorial(int a); int Fibonacci(a);long Hanoi(a); void main(){ } 函数递归调用: ...