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 ...
随机推荐
- JAVA记事本的图形用户界面应用程序含过滤
JAVA记事本的图形用户界面应用程序 过滤 题目简介: 整体分析: 实验代码: package note; import java.awt.EventQueue; import java.awt.ev ...
- POJO是什么,javabean是什么,以及POJO与javabean的区别
POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称.使用POJO名称是为了避免和EJB混淆起来, 而 ...
- JS事件中级 --- 拖拽
http://bbs.zhinengshe.com/thread-1200-1-1.html 要求:实现div块的拖拽 原理:拖拽过程中鼠标点和div块的相对位置保持不变. 需要理解三点: 1. 为什 ...
- 了解XPath与XPath轴
XPath 是一门在 XML 文档中查找信息的语言.XPath 用于在 XML 文档中通过元素和属性进行导航. 节点(Node) 在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理 ...
- Pandas使用细则
本文介绍pandas的使用,总结了我在机器学习过程中常使用到的一些方法等. #pandas学习 import pandas as pd import numpy as np import seabor ...
- 修改iframe内元素的样式
$('iframe').load(function () { var x = document.getElementsByTagName('iframe')[0]; var y = (x.cont ...
- WijmoJS 以声明方式添加 Vue 菜单项
WijmoJS 以声明方式添加 Vue 菜单项 在V2019.0 Update2 的全新版本中,Vue框架下 WijmoJS 的前端UI组件功能得到再度增强. 如今,向wj菜单组件添加项的方法将不限于 ...
- Hadoop三种架构介绍及搭建
apache hadoop三种架构介绍(standAlone,伪分布,分布式环境介绍以及安装) hadoop 文档 http://hadoop.apache.org/docs/ 1.StandAlo ...
- 建立分表sql执行语句批量生成工具(自创)
public void addTable (){ String add=""; for(int i=1;i<13;i++){ for(int j=0;j<60 ...
- Robot Framework(三)项目实践出现的问题以及解决方法
导航: 1.元素定位失败 2.系统自带的确认弹窗 3.ElementNotVisibleException: Message: element not visible 1.元素定位失败(使用frame ...