ssm开发前端

<template>
    <div>
        <h1 align="center">SSM阶段机试,ts={{ts}}</h1>
        <!-- 搜索栏 -->
        <el-form :inline="true">
            <el-form-item>
                <el-input v-model="bookname" placeholder="请输入书本名称"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="query">查询</el-button>
                <el-button type="success" @click="open">新增</el-button>
            </el-form-item>
        </el-form>
        <!-- 数据表格 -->
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="id" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="bookname" label="名称" width="180">
            </el-table-column>
            <el-table-column prop="price" label="价格">
            </el-table-column>
            <el-table-column prop="booktype" label="类型">
            </el-table-column>
        </el-table>
        <!-- 弹出框 -->
        <el-dialog title="新增" :visible.sync="dialogFormVisible">
            <el-form :model="ff" :rules="rules" ref="ff" label-width="100px" class="demo-ruleForm">
                <el-form-item label="名称" prop="bookname">
                    <el-input v-model="ff.bookname"></el-input>
                </el-form-item>
                <el-form-item label="价格" prop="price">
                    <el-input v-model="ff.price"></el-input>
                </el-form-item>
                <el-form-item label="类型" prop="booktype">
                    <el-input v-model="ff.booktype"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="add">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data: function() {
            return {
                ts: new Date().getTime(),
                bookname: '',
                tableData: [],
                dialogFormVisible: false,
                ff: {
                    bookname: '',
                    price: '',
                    booktype: ''
                },
                rules: {
                    bookname: [{
                        required: true,
                        message: '请输入书本名称',
                        trigger: 'blur'
                    }],
                    price: [{
                        required: true,
                        message: '请输入书本价格',
                        trigger: 'blur'
                    }],
                    booktype: [{
                        required: true,
                        message: '请输入书本类型',
                        trigger: 'blur'
                    }],
                }
            };
        },
        methods: {
            query: function() {
                //请求参数
                let params = {
                    bookname: this.bookname
                };
                //请求URL
                let url = this.axios.urls.QUERY;
                //发起请求
                this.axios.post(url, params).then(resp => {
                    console.log(resp.data);
                    this.tableData = resp.data.data;
                }).catch(err => {

                })
            },
            open: function() {
                this.dialogFormVisible = true;
                this.ff={
                    bookname: '',
                    price: '',
                    booktype: ''
                }
            },
            add: function() {
                this.$refs['ff'].validate((valid) => {
                    if (valid) {
                        let url = this.axios.urls.ADD;
                        this.axios.post(url, this.ff).then(resp => {
                            let data = resp.data;
                            if (data.success) {
                                this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                //关闭对话框
                                this.dialogFormVisible = false;
                                //刷新列表
                                this.query();
                            }
                        }).catch(err => {

                        })
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        }
    }
</script>

<style>
</style>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值