vue2对象丢失响应式解决办法

2023-12-26 16:40:01

<template>
  <div>
    {{dialogForm}} <div @click="updateDialogForm">99909009</div>
    <!-- Your component template here -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogForm: {
        returnNode: "",
        returnRatio: "",
        returnMoney: "",
        contractWaitReturnMoney: "",
        returnWay: "",
        returnCondition: "",
        remark: "",
      },
    };
  },
  methods: {
    updateDialogForm() {
      let newData={
        returnNode: "12",
        returnRatio: "23",
        returnMoney: "32",
        contractWaitReturnMoney: "32",
        returnWay: "32",
        returnCondition: "32",
        remark: "32",
      }
      // 遍历新数据对象,并使用 this.$set 更新 dialogForm
      Object.keys(newData).forEach((key) => {
        this.$set(this.dialogForm, key, newData[key]);
      });
    },
  },
  // Call this method whenever you want to update dialogForm with new data
  // For example, this.updateDialogForm({ returnNode: "new value", returnRatio: "new ratio", ... })
};
</script>

文章来源:https://blog.csdn.net/m0_47999208/article/details/135224594
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。