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

mixin conflict #20

Closed Pyro979 closed 5 years ago

Pyro979 commented 5 years ago

Love the library!

Ran into an issue using your library and trying to create my own mixin. I'm adding a currentEnumStore variable to data in my mixin. Works fine for regular components, but throws the following warning for the VRuntimeTemplate components.

[Vue warn]: The data property "currentEnumStore" is already declared as a prop. Use prop default value instead.

found in

---> <Anonymous>
       <VRuntimeTemplate>
         <Tiles> at src/views/rtf/tiles/Tiles.vue
           <RTF> at src/views/RTF.vue
             <App> at src/App.vue
               <Root>

for now I worked around it by checking if the variable exists, but it's not ideal.

    Vue.mixin({
      data() {
        let data = {};
        if (typeof this.currentEnumStore === "undefined")
          data.currentEnumStore = null;

        return data;
      },

I'm not sure if it's even possible to resolve this, since I'm assuming you grab every data and prop and pass them on, and once the template is rendered it tries to add them. But maybe there is a way to pass in global options to have a black list of data/props that shouldn't be proxied since they will be added?

Thoughts.

warrence commented 5 years ago

Im having the same problem as you, im getting tons of warning for all the function i declare globally in globals.js. Any workaround other that the solution above?

Pyro979 commented 5 years ago

@warrence just created a pull request #21 to hopefully resolve the issue. @alexjoverm please take a look to confirm my logic makes sense.

Solinx commented 5 years ago

I'm having the same issue here also. Thanks for creating the pull request @Pyro979! Haven't given it a try yet, but will do so tomorrow.

Solinx commented 5 years ago

@Pyro979 It didn't provide a solution for me unfortunately. However, I'm experiencing a slightly different issue. In my case the mixin provides methods. Also, I'm running Nuxt, which may be another factor.

While looking into the issue I found that (with your code) the methods are not actually passed through, but the error persists. This means my issue probably lies outside the scope of the VRuntime code.

Pyro979 commented 5 years ago

@Solinx have you tried just replacing the template directly in the code to narrow it down? I unfortunately don't have experience with Nuxt, so not sure how much I can help.

Solinx commented 5 years ago

The duplication error only occurs on pages with VRuntime. For now I'm just avoiding the use of global mixins. We use this dynamic component to display blog articles with embedded Vue templates from an api. There are other ways to make the mixin functionality available, but so far I've not found good alternatives to VRuntime.

Solinx commented 5 years ago

Argh... sorry, it looks like cache got the better of me earlier 😞 I'm not seeing any errors now. Many thanks! 👍

alexjoverm commented 5 years ago

Closed by #21