zoukankan      html  css  js  c++  java
  • vue项目---编辑与新增页

    vue项目

    在项目中,有很多管理系统类的项目,各有所不同! 

    在关于某个列表选择时,常常会有新增列表页面和编辑某一项页面,甚会有只可读的详情页!(实际上布局相差不大)

    对于编辑和新增页:

    <template>
      <div>
        <h1>{{ editId ? 编辑 : 新增 }}</h1>
        <div><button @click="save">保存</button><button @click="cancel">取消</button></div>
      </div>
    </template>
    <script>
    export default {
      data() {
        return {
          editId: null
        };
      },
      methods: {
        reset() {},
        save() {
          // 验证数据是否已填,保存数据
          const params = form;
          if (this.editId) {
            //   存在id,为编辑请求
            getUpdate(params).then(res => {
              console.log(res);
            });
          } else {
            //   不存在id,为新增请求接口
            getCreate(params).then(res => {
              console.log(res);
            });
          }
          //   重置
          this.reset();
        },
        cancel() {
          this.$router.back(-1);
        }
      },
      mounted() {
        this.reset();
        // 根据传入的id,渲染编辑页数据
        if (this.$router.currentRoute.query.id) {
          this.editId = parseInt(this.$router.currentRoute.query.id);
          if (!Number.isNaN(this.editId)) {
            getId({ id: this.editId }).then(res => {
              console.log(res);
            });
          }
        }
      }
    };
    </script>
    

      

    集思广益,仅供学习,侵权即删!!
  • 相关阅读:
    5.7填数字游戏求解
    5.6判断回文数字
    5.5百钱买百鸡问题
    5.4三色球问题
    5.3哥德巴赫猜想的近似证明
    5.2求两个数的最大公约数和最小公倍数
    5.1舍罕王的失算
    4.19递归反向输出字符串
    Elasticsearch 安装
    linux 安装nginx步骤
  • 原文地址:https://www.cnblogs.com/hudunyu/p/13440727.html
Copyright © 2011-2022 走看看