zoukankan      html  css  js  c++  java
  • vue前端与django后端数据交互

    //把数据传到路径为/airCdt/的django后端函数进行数据处理

    onSubmit(){
    const dict={
    'floor': this.formLabelAlign.floor,
    'room': this.formLabelAlign.room,
    'status': this.formLabelAlign.status,
    'mode': this.formLabelAlign.mode,
    'temp': this.formLabelAlign.temp,
    'level': this.formLabelAlign.level,
    };
    $.get("/airCdt/", dict, function (ret) {

    // console.log(ret);
    $("#respond").html(ret);
    });


    },

    //获得数据
    $.get("/api/floor2_ajax/", (ret) =>{
    var data = JSON.parse(ret);
    this.tableData[3]["data"] = Number(data[room-1]["fields"]["temp"]).toFixed(1);
    localStorage.setItem("temp_8229",this.tableData[3]["data"]);
    var status = data[room-1]["fields"]["status"];
    if (status =='0'){
    this.tableData[0]["data"] = '关';
    }
    else if(status =='1'){
    this.tableData[0]["data"] = '开';
    }
    else{this.tableData[0]["data"]='未知';}
    localStorage.setItem("status_8229",this.tableData[0]["data"]);
    var mode = data[room-1]["fields"]["mode"];
    if (mode =='1'){
    this.tableData[1]["data"] = '制热';
    }
    else if(mode =='2'){
    this.tableData[1]["data"] = '制冷';
    }
    else if(mode=='3'){
    this.tableData[1]["data"] = '除湿';
    }
    else{this.tableData[1]["data"] = '未知';}
    localStorage.setItem("mode_8229",this.tableData[1]["data"]);
    var level = data[room-1]["fields"]["level"];
    if (level =='1'){
    this.tableData[2]["data"] = '低速';
    }
    else if(level =='2'){
    this.tableData[2]["data"] = '中速';
    }
    else if(level=='3'){
    this.tableData[2]["data"] = '高速';
    }
    else if(level=='4'){
    this.tableData[2]["data"]= '自动';
    }
    else{this.tableData[2]["data"] = '未知';}
    localStorage.setItem("level_8229",this.tableData[2]["data"]);
    this.tableData[5]["data"] = data[room-1]["fields"]["co2"];
    localStorage.setItem("co2_8229",this.tableData[5]["data"]);
    this.tableData[7]["data"] = Number(data[room-1]["fields"]["tvoc"]).toFixed(3);
    localStorage.setItem("tvoc_8229",this.tableData[7]["data"]);
    this.tableData[4]["data"] = Number(data[room-1]["fields"]["hum"]).toFixed(1);
    localStorage.setItem("hum_8229",this.tableData[4]["data"]);
    this.tableData[6]["data"] = data[room-1]["fields"]["pm25"];
    localStorage.setItem("pm25_8229",this.tableData[6]["data"]);
    })

    # 发送给前端的每层楼的ajax数据路由
    path('api/floor2_ajax/', api.floor2_Data),
    path('floor2/', views.floor2),
    path('api/floor3_ajax/', api.floor3_Data),
    path('floor3/', views.floor3),
    path('api/floor4_ajax/', api.floor4_Data),
    path('floor4/', views.floor4),
    path('api/floor5_ajax/', api.floor5_Data),
    path('floor5/', views.floor5),
    path('api/floor6_ajax/', api.floor6_Data),
    path('floor6/', views.floor6),
    path('test/', views.TesT),
    # 接收前端数据的路由
    path('airCdt/', views.airCdt),
    path('freshAir/', views.freshAir),

    视图中的view
    # 获得前端数据
    def airCdt(request):

    floor = request.GET['floor']
    room = request.GET['room']
    status = request.GET['status']
    mode = request.GET['mode']
    temp = request.GET['temp']
    level = request.GET['level']
    print(floor, room, status, mode, temp, level)
      # 进行数据处理
    return HttpResponse("空调ok")
  • 相关阅读:
    分享几个个人觉得挺漂亮的导航 Jquery
    C#程序打成 一键安装包InstallShield
    腾讯显IP的API
    C#综合揭秘——细说事务
    2012最新JQuery插件
    Flex各种用法及使用技巧一
    win7管理员账户的启用方法
    禁用win7休眠
    win7下移动文件夹
    win7下转移搜狗文件临时文件夹和IE临时文件夹的方法
  • 原文地址:https://www.cnblogs.com/nuister/p/11564597.html
Copyright © 2011-2022 走看看