~祝今在 2022-09-05 15:55 采纳率: 66.7%
浏览 26

vue代码中无法调用form.host数据,这是为什么?

在写vue前端页面时无法调用数据form.host
问题相关代码

img

img

<template>
  <div class="app-container">
    <h1>OpenTSDB基础任务</h1>
    <el-form :inline="true" boder :model="queryParams" class="demo-form-inline">


      <el-form-item label="开始时间">
        <el-col :span="18">
          <el-date-picker
            type="date"
            placeholder="开始时间"
            v-model="queryParams.startTime"
            style="width: 100%;"
            value-format="timestamp"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-col :span="18">
          <el-date-picker
            type="date"
            placeholder="结束时间"
            v-model="queryParams.endTime"
            style="width: 100%;"
            value-format="timestamp"
          >
          </el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="queryParams.type">
          <el-option label="全部" value="all"></el-option>
          <el-option label="CPU" value="cpu"></el-option>
          <el-option label="内存" value="storage"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="handleAdd">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dbList" border>
      <el-table-column label="序号" align="center" type="index" :index="indexMethod" width="100"/>
      <el-table-column label="日期" align="center" prop="date" width="100">
        { parseTime(scope.row.date, '{y}-{m}-{d}') }}
                </template>-->
      </el-table-column>
      <el-table-column label="主机" align="center" prop="host" width="100">
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.type=='storage'">内存</span>
          <span v-else>CPU</span>
        </template>
      </el-table-column>
      <el-table-column label="最高性能值" align="center" prop="value" width="100"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="主机IP" prop="host">
          <el-input v-model="message" style="width: 100%;"/>
          {{form1.host}}{{form.host}}
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="form.type" placeholder="请输入类型" style="width: 100%;">
            <el-option
              v-for="dict in [{label:'全部',value:'all',key:0},{label:'CPU',value:'cpu',key:1},{label:'内存',value:'storage',key:2}]"
              :key="dict.key"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-date-picker
            v-model="form.time"
            type="datetime"
            placeholder="请输入时间"
            format="yyyy-MM-dd HH:mm:ss"
            style="width: 100%;"
            value-format="timestamp">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="性能值" prop="value">
          <el-input v-model="form.value" placeholder="请输入性能值" style="width: 100%;"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
// import {listDB, getDB, addDB, updateDB} from "@/api/openTSDB";
import axios from "axios";

export default {
  name: "OpenTSDB",
  mounted() {//钩子函数
  },
  created() {
    this.getList();
    this.queryParams.type = "all";
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // openTSDB表格数据
      dbList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        startTime: '',
        endTime: '',
        type: 'all',
        host:"192.16.13.188"
      },
      message:"nihao",
      // 表单参数
      form1: {
        host:"192form1"
      },
      form: {
        host:"192form"
      },
      // 表单校验
      rules: {
        /*host: [
          { required: true, message: "主机IP不能为空", trigger: "blur" }
        ],*/
        time: [
          {required: true, message: "时间不能为空", trigger: "change"}
        ],
        type: [
          {required: true, message: "类型不能为空", trigger: "change"}
        ],
        value: [
          {required: true, message: "性能值不能为空", trigger: "blur"}
        ]
      }
    }
  }
  ,
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      this.$axios.get('/api/opentsdb/list',{params:this.queryParams}).then(response => {
        console.log(response.data.length);
        this.dbList = response.data;
        this.total = response.data.length;
        this.loading = false;
        }
      );
    }
    ,
    /** 搜索按钮操作 */
    onSubmit() {
      console.log('submit!');
      this.queryParams.pageNum = 1;
      this.getList();
    }
    ,
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
      console.log(this.form.host)
    }
    ,
// 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    }
    ,
// 表单重置
    reset() {
      this.form = {
        host: undefined,
        type: undefined,
        time: undefined,
        value: undefined,
      };
      // this.resetForm("form");
    }
    ,
    indexMethod(index) {
      return index + 1;
    }
    ,
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log(this.form.host)
          /*this.$axios.post('/api/opentsdb/add',this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });*/
          /*if (this.form.noticeId != undefined) {
            updateDB(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.$axios.post('/api/opentsdb/add',this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }*/
        }
      });
    }
    ,
  }
}
</script>
运行结果及报错内容

img

img

  • 写回答

1条回答 默认 最新

  • 雾里桃花 2022-09-05 15:59
    关注

    你给设置成undefined了

    img

    评论

报告相同问题?

问题事件

  • 创建了问题 9月5日

悬赏问题

  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存
  • ¥15 无法装系统,grub成了顽固拦路虎
  • ¥15 springboot aop 应用启动异常
  • ¥15 matlab有关债券凸性久期的代码
  • ¥15 lvgl v8.2定时器提前到来
  • ¥15 qtcp 发送数据时偶尔会遇到发送数据失败?用的MSVC编译器(标签-qt|关键词-tcp)
  • ¥15 cam_lidar_calibration报错