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 ...
随机推荐
- JndiObjectFactoryBean 配置数据源
转: JndiObjectFactoryBean 配置数据源 2017年08月29日 22:04:28 病毒先生 阅读数:7338 版权声明:本文为博主原创文章,未经博主允许不得转载. https ...
- 阶段3 3.SpringMVC·_04.SpringMVC返回值类型及响应数据类型_1 搭建环境
创建项目 使用骨架,创建webapp 为了创建项目更快速maven设置 archetypeCatalog internal 修改编译的版本 从昨天的课程内复制 相关的坐标.上面是版本锁定. 复制前端的 ...
- JAVA VUser
JAVA VUser 一.java虚拟用户协议 java虚拟用户脚本主要有Java Vuser.Corba-Java.RMI-Java.EJB等类型.这些类型的虚拟用户脚本均可以用java语言来手工编 ...
- JavaScript(1):Base/Tips
目录 输出 全局变量 字符串 类型及转换 变量提升 严格模式 表单验证 (1) 输出 <!DOCTYPE html> <html> <body> <p> ...
- 掌握Pod-Pod调度策略
一 Pod生命周期管理 1.1 Pod生命周期 Pod在整个生命周期过程中被系统定义了如下各种状态. 状态值 描述 Pending API Server已经创建该Pod,且Pod内还有一个或多个容器的 ...
- Django Model 基础数据库操作应用
https://blog.csdn.net/Mrzhangjwei/article/details/53001841 一.数据库操作1.创建model表 基本结构: from django.db im ...
- PI膜概述
一.概述 1.简述 聚酞亚胺薄膜又称PI薄膜(polyimide filin)是一种含有酞亚胺或丁二酞亚胺的绝缘类高分子材料.是目前工程塑料中耐热性最好的品种之一. 2.发展简史 1908年,PI聚合 ...
- android webview 访问 https 页面
在android 中利用webview 控件进行开发过程中,可能会遇到 webview 访问不了https://的页面如 https://www.google.com.hk 重写onReceivedS ...
- 解析之Apache解析
- [python] super() 用法
问题的发现与提出 在Python类的方法(method)中,要调用父类的某个方法,在Python 2.2以前,通常的写法如下: class A: def __init__(self): print & ...