VUE+Django前后端分离-第四部分【后台数据如何展示在前端table表格中】

2022/8/16 23:22:55

本文主要是介绍VUE+Django前后端分离-第四部分【后台数据如何展示在前端table表格中】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、后端返回数据

后端返回的数据格式如下:

{
    "msg": "success",
    "data": [
        {
            "rule": 1,
            "result": "exception",
            "remark": "334668"
        },
        {
            "rule": 2,
            "result": "planid",
            "remark": "AR220811000002"
        }
    ]
}

二、前后端数据交互

 

 三、前端代码

<template>
    <div>
        <h3>推置引擎测试界面</h3>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="异常id">
                <el-input v-model="formInline.exceptionid" placeholder="异常id"></el-input>
            </el-form-item>
            <el-form-item label="方案id">
                <el-input v-model="formInline.planid" placeholder="方案id"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table :data="tableData" style="width: 90%">
            <el-table-column prop="rule" label="规则" width="180">
            </el-table-column>
            <el-table-column prop="result" label="结果" width="180">
            </el-table-column>
      <el-table-column prop="remark" label="备注" width="600">
            </el-table-column>
        </el-table>
    </div>

</template>

<script>
    export default {
        data() {
            return {
                formInline: {
                    exceptionid: '',
                    planid: '',
                    rule: '',
                    result: '',
                    remark:'',
                },
                requestpara: {
                    exceptionid: '',
                    planid: '',
                },
                tableData: [],
            }
        },
        methods: {
            onSubmit() {
                this.requestpara.exceptionid = this.formInline.exceptionid
                this.requestpara.planid = this.formInline.planid
                this.$http.post('http://127.0.0.1:8000/calculate_testengine/',this.requestpara)
                  .then((response) => {
                  var res = JSON.parse(response.bodyText)
                  console.log(res)
                  if (res.msg == 'success'){
            this.tableData = res.data;
                  } else {
                    console.log(res.data)
                  }
                  }
                );
            }
        }
    }
</script>

<style>

</style>

 



这篇关于VUE+Django前后端分离-第四部分【后台数据如何展示在前端table表格中】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程