vue自定义弹框的增删改 以及数据传输 操作

弹框的增删改 以及数据传输 操作

  • 首先在父级页面用’scope’包裹你要操作的按钮等元素
          <template slot-scope="scope">
          <el-button
              @click="updateCompany(scope.row)"
              >修改</el-button
            >
          </template>
  • 在对应的methods中 接收传过来的row 然后传递方法到store中
    updateCompany(row) {
      this.$store.commit("addCompanyDesign", "修改");
      this.$store.commit("checkCompanyData", row);
    }

  • 自己页面也就是对应的弹框页面中 给确定或保存按钮添加点击事件
   <el-button type="success" @click="submitForm('postData')" round
          >确 定{{ this.companyDatas.id }}</el-button
        >

  • 并把data中的数据传过去
    (这里的 this.companyDatas.id 中companyDatas在该页面中data定义好的 这里只是测试id是否传了进来)

  • watch监听时 要添加对应的监听对象

  watch: {
      //监听弹出框
    "$store.state.company.addCompanyDesign": {
      handler(val) {
        this.dialogVisible = val;
        this.desginTitle = this.$store.state.company.designType + "公司信息";
      },
    },
    //对store中对应方法 也就是自己加进去的进行监听
    "$store.state.company.checkData": {
      handler(val) {
        console.log(val, "点击对象");
        this.companyDatas = val;
      },
    },
    //对postDate进行监听
    postData: {
      handler(val) {
        console.log(val, "监听表单");
        if (JSON.stringify(val) != "{}") {
          console.log("符合条件,进行存储");
          this.$store.commit("setCompanyDesign", val);
        }
      },
      deep: true  //深度监听
    }
  }

  • 上面用this. 调用的都会在data中定义!!

  • 子页面要写上这个方法 并在created中调用

   judgeFormData() {
      if (this.$store.state.company.addCompanyDesign == true) {
        this.dialogVisible = true;
        this.postData = this.$store.state.company.companyData;
      }
    }

  created() {
    this.judgeFormData();
  }
  • 然后在子页面就可以进行增删改相应的方法了

  • store中 在子页面用到的数据和方法也要记得写上

 checkCompanyList(state, payload) {
   state.companyList = payload
 }
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值