alexjoverm / v-runtime-template

Vue component for compiling templates on the fly using a v-html like API
MIT License
605 stars 70 forks source link

v-runtime-template doesn't see refs in the template. #80

Open SuperIbm opened 3 years ago

SuperIbm commented 3 years ago

If you have ref parameters in a template that you want to compile with v-runtime-template you cannot have access to the element with this.$refs in your code.

SuperIbm commented 3 years ago

2021-02-26_16-30-52 2021-02-26_16-30-37

vin-ni commented 3 years ago

I have the same issue. When I do this.$refs.runtimetemplate.$children[0].$children[0].function() it runs the function but instantly rerenders new components with the original state. (it seems so, as they have new _uids)

vin-ni commented 3 years ago

I ended up ditching v-runtime-template and doing something like that:

      <template v-for="block in content.body" >
        <component
          :is="'templatename'"
          :key="block.date"
          :block="block"
        ></component>
      </template>
jourdain commented 2 years ago

I use the helper function and it is working fine for me but I need to attach a ref to the template.

getRef(ref) {
          const { root } = this.$refs;
          if (root.$refs && root.$refs[ref]) {
            return root.$refs[ref];
          }
          return root.$children[0].$refs[ref];
},

while using <v-runtime-template ref="root" ... />