v-runtime-template and vuex cause infinite update loop

≯℡__Kan透↙ 提交于 2021-01-29 08:31:41

问题


I came across an infinite loop that really confused me. I used v-runtime-template to load dynamic forms, everything works fine when I use static data, but switches to an infinite loop after getting data from vuex.

I have written two examples with CodeSandbox, but note that clicking on Demo2 may cause the browser to die.

The loading of data needs to be done through vuex. How to solve the problem of infinite loop, I look forward to your help.


回答1:


I have solved this problem. defining a sub-component to load v-runtime-template, get data in the parent component and passing it to sub-components via props. Code is like this:

<template>
  <form data-vv-scope="custom-form" v-if="html">
    <form-content :html="html" :data="data" :permission="permission" />
  </form>
</template>

<script>
import FormContent from "@/components/FormContent.vue";
import { mapState } from "vuex";

export default {
  name: "demo2",
  computed: mapState({
    html: state => state.html,
    data: state => state.data,
    permission: state => state.permission
  }),
  components: {
    FormContent
  },
  created() {
    this.$store.dispatch("loadForm");
  }
};
</script>


来源:https://stackoverflow.com/questions/55158447/v-runtime-template-and-vuex-cause-infinite-update-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!