用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. Mysqlfunc.c

    int rc;int db_connection;char *server = "192.168.139.207"; // 数据库的ip地址char *user = "c ...

  2. MySQL使用order by field()自定义排序

    MySQL的自定义排序和Oracle相比,要简单得多. 假设在表v_education的列schoolRecord中,有以下字段:'小学','初中','高中','专科','本科','硕士','博士'. ...

  3. jmeter设置中文语言

    1.在jmeter的bin目录下找到  jmeter.properties  文件并打开 2.搜索关键字 “language”,将37行(以搜索到的位置为准)改成下图所示:language=zh_CN ...

  4. Leetcode之动态规划(DP)专题-413. 等差数列划分(Arithmetic Slices)

    Leetcode之动态规划(DP)专题-413. 等差数列划分(Arithmetic Slices) 如果一个数列至少有三个元素,并且任意两个相邻元素之差相同,则称该数列为等差数列. 例如,以下数列为 ...

  5. so的封装和使用

    背景 在linux平台下,要实现函数的封装,一般采用的是so动态库的形式 实现了函数的封装就意味着实现过程的隐藏 可以实现跨平台和跨语言的使用 实施步骤 生成so动态库 编写相应的c文件代码,实现函数 ...

  6. NoSQL--couchdb

    Couchdb CouchDB是Apache组织发布的一款开源的.面向文档类型的NoSQL数据库.由Erlang编写,使用json格式保存数据.CouchDB以RESTful的格式提供服务可以很方便的 ...

  7. VS2017:"64位调试操作花费的时间比预期要长",无法运行调试解决办法

    关于这个问题网上搜了好久,参考http://www.yishimei123.com/network/685.html这篇文章,最后终于解决了,在此表示非常感谢! 我的环境是:win10+VS2017 ...

  8. [爬虫] BeautifulSoup库

    Beautiful Soup库基础知识 Beautiful Soup库是解析xml和html的功能库.html.xml大都是一对一对的标签构成,所以Beautiful Soup库是解析.遍历.维护“标 ...

  9. 设计模式在 Spring 框架中的良好应用

    在开始正文之前,请你先思考几个问题: 你项目中有使用哪些 GOF 设计模式 说一说 GOF 23 种设计模式的设计理念 说说 Spring 框架中如何实现设计模式 假设我是面试官问起了你这些面试题,你 ...

  10. P1004方格取数

    这是提高组得一道动态规划题,也是学习y氏思考法的第一道题. 题意为给定一个矩阵,里面存有一些数,你从左上角开始走到右下角,另一个人从右下角开始走到左上角,使得两个人取数之和最大,当然一个数只可以取走一 ...