用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的更多相关文章

  1. Vue + TypeScript + ElementUI 封装表头查询组件

    前段时间有朋友私信我 Vue + TypeScript 的问题,然后就打算写一篇 Vue + TypeScript 封装组件的文章 正好公司项目中需要封装一个表头查询组件,就拿出来分享一下~ 组件的整 ...

  2. vue + typescript 项目起手式

    https://segmentfault.com/a/1190000011744210 2017-10-27 发布 vue + typescript 项目起手式 javascript vue.js t ...

  3. Vue+Typescript中在Vue上挂载axios使用时报错

    Vue+Typescript中在Vue上挂载axios使用时报错 在vue项目开发过程中,为了方便在各个组件中调用axios,我们通常会在入口文件将axios挂载到vue原型身上,如下: main.t ...

  4. Vue + TypeScript + Element 搭建简洁时尚的博客网站及踩坑记

    前言 本文讲解如何在 Vue 项目中使用 TypeScript 来搭建并开发项目,并在此过程中踩过的坑 . TypeScript 具有类型系统,且是 JavaScript 的超集,TypeScript ...

  5. 使用Vue-cli3搭建Vue+TypeScript项目

    一,创建项目 使用 npm 安装 vue-cli 3 和typescript npm i -g @vue/cli typescript 使用vue create命令快速搭建新项目的脚手架 vue cr ...

  6. almost最好的Vue + Typescript系列02 项目结构篇

    基于vue-cli 3.x,配合typescript的环境构建的新vue项目,跟以前的结构相比,有了一些变化,下面我们来简单的了解一下 基本结构: node_modules: 项目中安装的依赖模块 p ...

  7. vue+typescript基础练习

    环境 win10 node -v 8.9.3 vue-cli 3.4 typescript 3.1.5 编辑器 vscode 目标 使用vuecli工具,建立一个项目,使用typescript.并实现 ...

  8. Vue+Typescript项目中使用echarts

    方案一:推荐 在typescript+Vue的项目中引用echarts,为了加强引用,引入echarts和@types/echarts两个包,一个是工程依赖,一个是声明依赖. npm install ...

  9. vue+typescript入门学习

    最近想要结合vue学习typescript,了解到vue2.5之后开始支持typescript,就像拿vue学习一下,首先要解决的就是环境的搭建,略微麻烦,如果想要自己体验一把,可以参考这篇文章htt ...

随机推荐

  1. springboot集成springcloud,启动时报错java.lang.AbstractMethodError: null

    出现这个问题是springboot和springcloud的版本不匹配. 我此处使用了springboot 2.0.4.RELEASE,springcloud 使用了Finchley.SR2. 修改方 ...

  2. Python 输出时去掉列表元组外面的方括号与圆括号

     

  3. JavaScript基础入门08

    目录 JavaScript 基础入门08 DOM 介绍 绑定事件 给一组元素绑定事件 节点 节点树 节点类型 选取文档内容 通过id选取元素 通过指定的标签名选取元素 用指定的css类来选取元素 通过 ...

  4. RDD实例

    实例一: teacher.log http://bigdata.baidu.cn/zhangsan http://bigdata.baidu.cn/zhangsan http://bigdata.ba ...

  5. DFS(深度优先搜索)和BFS(广度优先搜索)

    深度优先搜索算法(Depth-First-Search) 深度优先搜索算法(Depth-First-Search),是搜索算法的一种. 它沿着树的深度遍历树的节点,尽可能深的搜索树的分支. 当节点v的 ...

  6. unsigned char 与unsigned long互换

    unsigned long UCharToULong(unsigned char * pucVar ){unsigned long ulTemp=0;ulTemp=(unsigned long)(*p ...

  7. MFC之MessageBox、AfxMessageBox用法

    在软件中我们经常会弹出个小窗口,给一点点提示.这就会用到消息对话框. 在Win32 API程序中只有MessageBox这一种用法. 而在MFC中就有三各方法: 1.调用API中的MessageBox ...

  8. Tableau常用图表

    条形图: 饼图: 调整大小: 折线图: 面积图: 组合图: 文本表: 突出显示表: 直方图: 气泡图: 散点图:

  9. java 统计素数个数问题

    题目:判断101-200之间有多少个素数,并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数. package Study ...

  10. # Pycharm打造高效Python IDE

    Pycharm打造高效Python IDE 建议以scientific mode运行,在科学计算时,可以方便追踪变量变化,并且会提示函数的用法,比普通模式下的提示更加智能,一般在文件中引入了numpy ...