Vue使用本地数据 回填表单

时间:2025-02-14 11:35:22

发送

  // 编辑
    handleEdit(row) {
      // 把这一行的数据存入本地
      window.sessionStorage.setItem("row", JSON.stringify(row));

      // 跳转到编辑页面
      this.$router.push("/home/goodsedit");
    },

接收

 created() {
    // 获取本地数据
    let row = JSON.parse(sessionStorage.getItem("row"));
    // 使用本地数据 回填表单
    this.goodsAddForm.goodsname = row.goodsname;
    this.goodsAddForm.goodscategory = row.goodscategory;
    this.goodsAddForm.goodsfeature = JSON.parse(row.goodsfeature);
    this.goodsAddForm.imgUrl = row.imgUrl;
    //  = row.;
    this.goodsAddForm.goodsdesc = row.goodsdesc;
    row.standard = JSON.parse(row.standard);
    // 判断单规格还是多规格
    if (row.standard.length > 1) {
      //  // 多规格
      // tableData: [
      //   { goodsstandard: "默认", packingexpense: 0, goodsprice: 20 }
      // ]
      console.log(row.standard);

      this.goodsAddForm.goodsstandard = "多规格";
      this.goodsAddForm.tableData = row.standard;
    } else {
      this.goodsAddForm.packingexpense = row.standard[0].packingexpense;
      this.goodsAddForm.goodsprice = row.standard[0].goodsprice;
    }
  }