Code Monkey home page Code Monkey logo

v-runtime-template's Introduction

v-runtime-template

npm npm Donate

A Vue.js components that makes easy compiling and interpreting a Vue.js template at runtime by using a v-html like API.

Do you know VueDose? It's where you can learn tips about the Vue.js ecosystem in a concise format, perfect for busy devs! ๐Ÿฆ„

See Demo on CodeSandbox

Motivation

This library solves the case where you get a vue-syntax template string on runtime, usually from a server. Think of a feature where you allow the user to create their own interfaces and structures. You save that as a vue template in your database, which your UI will request later. While components are pre-compiled at build time, this case isn't (since the template is received at runtime) and needs to be compiled at runtime.

v-runtime-template compiles that template and attaches it to the scope of the component that uses it, so it has access to its data, props, methods and computed properties.

Think of it as the v-html equivalent that also understands vue template syntax (while v-html is just for plain HTML).

Getting Started

Install it:

npm install v-runtime-template

You must use the with-compiler Vue.js version. This is needed in order to compile on-the-fly Vue.js templates. For that, you can set a webpack alias for vue to the vue/dist/vue.common file.

For example, if you use the Vue CLI, create or modify the vue.config.js file adding the following alias:

// vue.config.js
module.exports = {
  runtimeCompiler: true
};

And in Nuxt, open the nuxt.config.js file and extend the webpack config by adding the following line to the extend key:

// nuxt.config.js
{
  build: {
    extend(config, { isDev, isClient }) {
      config.resolve.alias["vue"] = "vue/dist/vue.common";
      // ...

Usage

You just need to import the v-runtime-template component, and pass the template you want:

<template>
	<div>
		<v-runtime-template :template="template"></v-runtime-template>
	</div>
</template>

<script>
import VRuntimeTemplate from "v-runtime-template";
import AppMessage from "./AppMessage";

export default {
  data: () => ({
    name: "Mellow",
    template: `
      <app-message>Hello {{ name }}!</app-message>
    `
  }),
  components: {
    AppMessage,
    VRuntimeTemplate
  }
};
</script>

The template you pass have access to the parent component instance. For example, in the last example we're using the AppMessage component and accessing the {{ name }} state variable.

But you can access computed properties and methods as well from the template:

export default {
  data: () => ({
    name: "Mellow",
    template: `
      <div>
        <app-message>Hello {{ name }}!</app-message>
        <button @click="sayHi">Say Hi!</button>
        <p>{{ someComputed }}</p>
      </div>
		`,
  }),
  computed: {
    someComputed() {
      return "Wow, I'm computed";
    },
  },
  methods: {
    sayHi() {
      console.log("Hi");
    },
  },
};

Limitations

Keep in mind that the template can only access the instance properties of the component who is using it. Read this issue for more information.

Comparison

v-runtime-template VS v-html

TL;DR: If you need to interpret only HTML, use v-html. Use this library otherwise.

They both have the same goal: to interpret and attach a piece of structure to a scope at runtime. The difference is, [v-html](https://vuejs.org/v2/api/#v-html) doesn't understand vue template syntax, but only HTML. So, while this code works:

<template>
	<div v-html="template"></div>
</template>

<script>
export default {
  data: () => ({
    template: `
      <a href="/mike-page">Go to Mike page</a>
    `

the following wouldn't since it uses the custom router-link component:

<router-link to="mike-page">Go to Mike page</router-link>

But you can use v-runtime-template, which uses basically the same API than v-html:

<template>
	<v-runtime-template :template="template"></v-runtime-template>
</template>

<script>
export default {
  data: () => ({
    template: `
      <router-link to="mike-page">Go to Mike page</router-link>
    `

v-runtime-template VS dynamic components (<component>)

Dynamic components have somewhat different goal: to render a component dynamically by binding it to the is prop. Although, these components are usually pre-compiled. However, the goal of v-runtime-template can be achieved just by using the component options object form of dynamic components.

In fact, v-runtime-template uses that under the hood (in the render function form) along with other common tasks to achieve its goal.

v-runtime-template's People

Contributors

alexjoverm avatar pyro979 avatar vicnovais avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

v-runtime-template's Issues

Can't find variable / use inside component

Great project, thanks for your work! ๐Ÿ‘
I try to use v-runtime-template inside a vuematerial/vue-material component, but I get the error ReferenceError: Can't find variable: visible.

<template>
     <!-- works: <v-runtime-template :template="template"></v-runtime-template> -->
    <md-card>
       <!-- doesn't work -->
        <v-runtime-template :template="template" />
    </md-card>
</template>

<script>
import Vue from 'vue'
import VRuntimeTemplate from 'v-runtime-template'

export default Vue.extend({
  components: {
    VRuntimeTemplate
  },
  data() {
    return {
      visible: true,
      template: '<p v-if="visible">Hello World!</p>'
    }
  }
})
</script>

Components get created twice inside template

Hello!

I'm having a problem with the v-runtime-template. Everytime a template gets inserted and rendered, it renders all the components inside it twice. I checked it with outputing the _uid of the component in the created() function and I two different instances of the component.

It's a problem for us, since some of the components that are inside the template are making REST request to the API, and we don't want to double the amount of them.

Any help or suggestions would be great!

Thanks!

Unable to pass dynamic props

Hi,
Thanks for this amazing package.

I was unable to pass props with dynamic component:

<template>
    <div>
        <v-runtime-template :template="template"></v-runtime-template>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                template: `<hero-component :message="'hello'" class="css-class"/>`
            }
        }
    }
</script>

<hero-component> never recieves message prop value, however i can see class is being pulled.

mixin conflict

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.

You library is amazing :)

This issue is only to congrats with you.

I've only a problem with this library, I use it in nuxt and one page loaded all work fine but if I try to refresh the page I got this warning:

The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside

, or missing . Bailing hydration and performing full client-side render.

Thanks you so much.

Create a directive instead of component

Just a thought, mainly inspired by the component name (v-render-template). Since v-html is a directive maybe it'd make sense to just create another directive instead of a full component?

Would that be at all possible?

I can clearly imagine myself using something like that instead of v-html

<div v-render-template="tpl" />

TypeError: Cannot read property 'asyncComputed' of undefined

i get

TypeError: Cannot read property 'asyncComputed' of undefined
    at Object.vueAsyncComputedInjectedDataFn [as data] (app.js:94221)
    at getKeysFromOptions (app.js:85826)
    at Proxy.render (app.js:85864)
    at VueComponent.Vue._render (app.js:105150)
    at VueComponent.updateComponent (app.js:103394)
    at Watcher.get (app.js:103748)
    at new Watcher (app.js:103737)
    at mountComponent (app.js:103401)
    at VueComponent../node_modules/vue/dist/vue.esm.js.Vue.$mount (app.js:109146)
    at VueComponent../node_modules/vue/dist/vue.esm.js.Vue.$mount (app.js:111545)

Every time i render something

Don't re-render on route change

I've got tabs that change the hash (or query) parameter of the route in order to be able to use the back button to return to previous tabs.

The content of the page stays the same when switching tabs, only some v-show changes on divs in the page.
The v-runtime-template-elements re-render all contents when the route-parameter changes, while other components don't do that. Is there a way to prevent this from happening?

The "PromoBox" component has been registered but not used

I have the following issue:

<template>
  <div>
    <v-runtime-template :template="html"></v-runtime-template>
  </div>
</template>

<script>
import VRuntimeTemplate from 'v-runtime-template'
import PromoBox from '@/components/base/promo-box'

export default {
  data () {
    return {
      html: '<div><promo-box></promo-box></div>'
    }
  },
  components: {
    VRuntimeTemplate,
    PromoBox
  }
}
</script>

This throws out error The "PromoBox" component has been registered but not used when building because <promo-box> component is not present in the template. Am I doing something wrong? I see no other people having this issue, am I missing something?

Using v-runtime-template within a slot

Just documenting this here as it took me awhile to solve this as it was not documented. Solved by code inspection.

If you want to pass some other props into the v-runtime-template's component, you can use

data: () => ({
    template: `<div>{{parentProp1}} {{prop}}</div>`,
}),
<v-runtime-template :template="template" :templateProps="{parentProp1, prop: parentProp2}"></v-runtime-template>

This seems to be required if you

  • trying to access v-for variables
  • using v-runtime-template within a slot, limiting you to parent component props, not slot scope

Hope this saves people some time in the future.

Error when using demo code with vuetify <v-card>

I am having problem using v-runtime-template with vuetify, and have make a minimal vuetify demo code as below:

<template>
  <div>
    <v-card>
      <v-card-text>
        <h3>Template code:</h3>
        <code v-html="template"></code>
        <br /><br /><br /><br />
        <h3>
          As you can see, the v-runtime-template component has access to this
          component scope, and updates accordingly.
        </h3>
        <input v-model="name" /> {{ name }}
        <v-runtime-template :template="template" />
      </v-card-text>
    </v-card>
  </div>
</template>

<script>
import VRuntimeTemplate from 'v-runtime-template';
import AppMessage from '@/components/AppMessage';

export default {
  data: () => ({
    name: 'Mellow',
    template: `
      <app-message>Hello {{ name }}!</app-message>
    `,
  }),
  components: {
    AppMessage,
    VRuntimeTemplate,
  },
};
</script>

The error given by the console is as follow:

[Vue warn]: Property or method "name" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

found in

---> <Anonymous>
       <VRuntimeTemplate>
         <VCard>
           <Template> at src/views/_Template.vue
             <VContent>
               <VApp>
                 <App> at src/App.vue
                   <Root>

[Vue warn]: Unknown custom element: <app-message> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

---> <Anonymous>
       <VRuntimeTemplate>
         <VCard>
           <Template> at src/views/_Template.vue
             <VContent>
               <VApp>
                 <App> at src/App.vue
                   <Root>

If I remove the <v-card> tag, everything will work as expected. I have no clue what is happening and hope if someone can shed some light.

Thanks!

Error handling

Hi there,

I am using v-runtime-template and it works like a charm! Thank you for your awesome work!

However, I'm not sure that the templates I'm rendering are correct. They can be valid or not and I have no control about that. I would like to execute some code (to display an error message) when they are not valid. The problem is that I can't catch the error to execute some code.I end up with this error :
"Failed to mount component: template or render function not defined.
And I can't catch it to execute some code.

Any ideas? If I solve this problem I may contribute to your lib to integrate error handling :D

vee-validate issue

Hello!

I'm having a little hard time trying to make vee-validate with this library, I'm trying to validate the dynamic template on the mounted function, but it seems to ignore that until I have changed the input.

Any ideas?

runtimeCompiler option

Just a small improvement suggestion for the documentation. If using vue-cli, then the runtimeCompiler option can be used: https://cli.vuejs.org/config/#runtimecompiler

Currently in Readme:

// vue.config.js
module.exports = {
  configureWebpack: {
    resolve: {
      alias: {
        vue$: "vue/dist/vue.common",
      },
    },
  },
};

Instead you can use:

// vue.config.js
module.exports = {
  runtimeCompiler: true
};

Access to global components

I have this working in a Vuetify app, but in order to use any of the Vuetify components in the template I need to include them in the component I have that uses it:

import { VBtn, VCard, VCardActions, VCardTitle, VImg } from "vuetify/lib"
...
    components: {
       VBtn, VCard, VCardActions, VCardTitle, VImg, ...

This is pretty long winded (and there are a lot of them).

Is there a way to be able to access all the global templates from the main Vue instance without referencing them explicitly here.

Issue with vuelidate

After installing vuelidate v-runtime-template now throws an error, they are in separate component.

    app.js:44784 [Vue warn]: Error in render: "TypeError: Cannot read property 'validations' of undefined"

found in

---> <VRuntimeTemplate

Any ideas? Is this a build problem?

How can I debug demo code on my computer?

I know question is a little of-topic, but I admired your work, you are filling the most important point for me.
I want to extend your code with router and vuex implemantation:

    1. Each page (vue component), and ,it's data will be served dynamically from server side,
    1. Page will be initialized with new VueComponent and its own data.

(I saw vue-router dependency on demo code but it is not used)

But I could not run demo code on my local machine
npm run
npm start
yarn start
static-serve
vue-serve
no one works, how can I debug demo code from my computer.

$refs undefined, while using v-runtime-template

<v-runtime-template :template='template'/>

data () {
    return {
      template: `
        <el-form :model='credentialsForm' :rules='credentialsRules' ref='credentialsForm' label-width='0' class='credentialsForm'> <el-form-item prop='name'> <el-input v-model='credentialsForm.name' type='text' placeholder='name'></el-input> </el-form-item> <el-form-item prop='type'> <el-select v-model='credentialsForm.type' placeholder='Select Type' class='full-width'> <el-option label='JDBC' value='jdbc'></el-option> <el-option label='LDAP' value='ldap'></el-option> <el-option label='Kerberos' value='kerberos'></el-option> </el-select> </el-form-item> <el-form-item prop='username'> <el-input v-model='credentialsForm.username' type='text' placeholder='username'></el-input> </el-form-item> <el-form-item prop='password'> <el-input v-model='credentialsForm.password' type='password' placeholder='password'></el-input> </el-form-item> <el-form-item class='float-right full-width'> <el-button type='primary' @click="addCredentials('credentialsForm')" class='float-right'>Create</el-button> <el-button @click="resetForm('credentialsForm')" class='float-right mr24'>Reset</el-button> </el-form-item> </el-form>
      `,
  }
}

addCredentials (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
 }

Error: 'Cannot read property 'validate' of undefined'

Any help?

Template allows multiple children but renders only the first

This happens with no warning and took me a minute to debug without error/warning messages in the console.

In a nutshell, if template: "<b>a</b>" then it's all good, but if template: "<a>b</a><b>a</b>", then only the first node (<a>b</a>) will be rendered, with no warning regarding wrapping templates into one root node being a requirement.

Dist files are not updated

It seems that the dist files where not updated since release 1.6.0. Could you do that please? I'm depending on them.

Always updating the dom

Constantly updates the entire dom in the v-runtime-template component itself. When you change the state in this component. Is it possible to solve this problem?

[NUXT] Error: Cannot read property '$metaInfo' of undefined

I am using latest Nuxt (2.8.1). I have installed v-runtime-template and when I try to use it in my template as a component and pass it the string that should be compiled, I get this error.

### Cannot read property '$metaInfo' of undefined.

I also added 'config.resolve.alias["vue"] = "vue/dist/vue.common";' into the nuxt config but it had no effect.

Any ideas about what might be causing this error and how to fix it?

Node version: 10.15.3

Not render props, methods inside..in components :: nuxt

Hi

Congratulations for the component!

I'm using nuxt and it works properly with the template for database.
I can not show props, methods ... inside of the components

Nuxt.config
image

Page script
image

Page template
image

To test mode...
I try to show the prop title_test inside of div and it does not work

More thanks!!

Is it possible to modify the parent model from the runtime template? It currently generates a vue warning and does not work.

I took the sample and moved the <input v-model="name"/> tag

<template>
	<div id="app">
    <h3>Template code: </h3>
    <code v-html="template"></code>
    <br><br><br><br>
    <h3>As you can see, the v-runtime-template component has access to this component scope, and updates accordingly. </h3>    
    <input v-model="name"/> {{name}}
		<v-runtime-template :template="template"></v-runtime-template>
	</div>
</template>

<script>
import VRuntimeTemplate from "v-runtime-template";
import AppMessage from "./AppMessage";

export default {
  data: () => ({
    name: "Mellow",
    template: `
      <app-message>Hello {{ name }}!
      <input v-model="name"/>
      </app-message>
    `
  }),
  components: {
    AppMessage,
    VRuntimeTemplate
  }
};
</script>

and moved it inline with the template. This does work does not work and Vue spits out this warning:

[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "name"

I'm wondering if there's any way around this warning or can this component only be used for read-only scenarios? I'm trying to allow customization of an input form.

Local state changes do not update runtime-template

I tried creating an "editable props" example using the runtime template to render the component on the fly. However, the runtime template creates an anonymous component with the "data" set from the "data()" function of the parent.

This never changes after component initialisation, therefore changes to parent state will never update in the anonymous component. I think it would be nice (maybe optionally) to allow updates to the component local state, just as you can update the template :)

Example
https://codesandbox.io/s/vjylx5kq4l

v-runtime-template.d.ts

Great package! Does anyone have a v-runtime-template.d.ts file so we can use this with TypeScript?

v-runtime-template with vue.esm.js?

First of all, thank you for your work, fantastic idea for a plugin!

My setup uses vue.esm.js, and I'm having trouble getting v-runtime-template to work. Is this an issue?

Console throws the following error:
Error in render: "TypeError: Cannot read property 'params' of undefined"

My code is as follows. After the npm installation, I import v-runtime-template in my parent component
import VRuntimeTemplate from "v-runtime-template"
where I call the component in the template section, just like in your example

<div>
  <v-runtime-template :template="template"></v-runtime-template>
</div>

with data properties

      name: "Mellow",
      template: `
        <p>Hello {{name}}!</p>
      `,

Is it a question of vue builds, or do I use v-runtime-template incorrectly in my code?

Btw I use Quasar UI, which handles webpack configuration and has the option of using vue.esm.js as a vue build.

Thanks a lot for any advice, would really like to use this plugin.

Update release on npm

I'm having some problems with mixins and duplicated props, which seems to be fixed in #20, but the new version is not available on npm yet. Any chance of pushing the update there as well?

Changelog

Hey !

Thank you for your component, it's great !

But it's hard to know what are the changes between versions because there is not CHANGELOG.md or any informations in the releases tab, is it possible for you to maintain this documentation ?

Thank you in advance

Trying to use this package, and got: this$1.$options.methods is undefined

Trying to use this package, and got: this$1.$options.methods is undefined

I have dynamic template like following:

sfsdfsd fsd <emoji emoji="joy">:joy:</emoji>

It doesn't render anything and I see error:

Vue warn]: Error in render: "TypeError: this$1.$options.methods is undefined"

found in

---> <VRuntimeTemplate>
       <TextareaEmojiPicker> at resources/assets/js/components/shared/TextareaEmojiPicker.vue
         <Thread> at resources/assets/js/components/messages/Thread.vue
           <Root> vendor.js:13031:15
    warn http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:13031
    logError http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:14280
    globalHandleError http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:14275
    handleError http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:14241
    _render http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:15919
    updateComponent http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:16417
    get http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:16815
    run http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:16890
    flushSchedulerQueue http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:16648
    nextTick http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:14376
    flushCallbacks http://localhost:8000/assets/js/vendor.js?id=284f3ece85c7235f90ba:14302

Dynamic vselect bind data dropdown css problem

<v-btn  @click="load">Success</v-btn>
</div>
<script> import Vue from "vue"; import Vuetify from "vuetify"; import VRuntimeTemplate from "v-runtime-template"; import "vuetify/dist/vuetify.min.css"; import 'material-design-icons-iconfont/dist/material-design-icons.css' Vue.use(Vuetify); const data = { template: '

v-runtime-template combobox problem sample!

', peopleModel : null } export default { data () { return data }, components: { VRuntimeTemplate }, methods: { load(){ var $this = this; setTimeout(function(){ data.people = [ { Name: 'OฤŸuz Nash', Id: 1}, { Name: 'Ali Connors', Id: 2 }, { Name: 'Trevor Hansen', Id: 3 }, { Name: 'Tucker Smith', Id: 4 }, { Name: 'Britta Holt', Id: 5 }, { Name: 'Jane Smith ', Id: 6 } ]; data.template = '
'; }, 1000); } } }; </script>

image

What is css problem?

Error in render: "TypeError: Cannot read property 'sayHi' of undefined"

i use v-runtimetempalte in nuxtjs
When I define a method, an error like title will be generated
Is there any way to solve it?

index.vue

<template>
  <section class="container">
    <div>
      <v-runtime-template :template="template"></v-runtime-template>
    </div>
  </section>
</template>

<script>
import VRuntimeTemplate from "v-runtime-template";
import Logo from '~/components/Logo.vue'

export default {
  components: {
    Logo,
    VRuntimeTemplate
  },
  methods: {
    sayHi() {
      console.log("Hi")
    }
  },
  data() {
    return {
      name:"abcd",
      template: `<div><logo :name="name"/></div>`,
    }
  },
}
</script>

Logo.vue

<template>
  <div class="VueToNuxtLogo">
    <div class="Triangle Triangle--two" />
    <div class="Triangle Triangle--one" />
    <div class="Triangle Triangle--three" />
    <div class="Triangle Triangle--four" />
  </div>
</template>

<script>
export default {
  props: ["name"],
  methods: {
    test() {
      console.log("test")
    },
  }
}
</script>

node_modules/v-runtime-template/dist/v-runtime-template.cjs.js:53:83

      //build new objects by removing keys if already exists (e.g. created by mixins)
      Object.keys($data).forEach(function (e) {if(typeof this$1.$data[e]==="undefined") { passthrough.$data[e] = $data[e]; }} );
      Object.keys($props).forEach(function (e) {if(typeof this$1.$props[e]==="undefined") { passthrough.$props[e] = $props[e]; }} );
      Object.keys(methods).forEach(function (e) {if(typeof this$1.$options.methods[e]==="undefined") { passthrough.methods[e] = methods[e]; }} );
      Object.keys(computed).forEach(function (e) {if(typeof this$1.$options.computed[e]==="undefined") { passthrough.computed[e] = computed[e]; }} );
      Object.keys(components).forEach(function (e) {if(typeof this$1.$options.components[e]==="undefined") { passthrough.components[e] = components[e]; }} );

      var methodKeys = Object.keys(passthrough.methods || {});
      var dataKeys = Object.keys(passthrough.$data || {});

package.json

  "dependencies": {
    "cross-env": "^5.2.0",
    "element-ui": "^2.4.11",
    "express": "^4.16.4",
    "nuxt": "^2.4.0",
    "v-runtime-template": "^1.6.2"
  },

Version number mismatch

The version tag says 1.6.0, but the comment in v-runtime-template.min.js says v1.5.3. Which is correct?

Thanks.

HTML isn't interpreted when defined as data/method/computed property

When using HTML directly in template, it's properly interpreted. When returning content with HTML from data/a method/a computed property, it's not.

In other words, this works:

<template>
  <v-runtime-template :template="template"></v-runtime-template>
</template

<script>
export default {
  data() {
    return {
      myVar: 'Hello'
    }
  },
  computed: {
    template() {
      return `<my-component><em>{{ myVar }}</em></my-component>`
    }
  }
}
</script>

But this doesn't:

<template>
  <v-runtime-template :template="template"></v-runtime-template>
</template

<script>
export default {
  data() {
    return {
      myVar: `<em>Hello</em>`
    }
  },
  computed: {
    template() {
      return `<my-component>{{ myVar }}</my-component>`
    }
  }
}
</script>

Is this a bug or is it a technical limitation? And if this is the latter, is there a way around it?

Thanks in advance!

Template is re-rendered every time the parent date changes

I'm not sure if this is intentional, but the template is re-rendered every time the parent data changes (understandably). This causes the components inside the template to be re-created again and for certain edge cases this can be undesirable.

Perhaps this should be added as a note some where if not already.

template compiler is not available

I'm getting this error:

`[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

found in

--->

at src/components/DocumentationContentWidget.vue
at src/views/DocumentationPage.vue
at src/App.vue
`

how to fix this?

Error when using v-render-template with vue-class-component

https://github.com/padcom/v-runtime-template-example-with-poi

Problem description

In src/index.js there are 2 imports.

//import App from './components/App1'
import App from './components/App2'

App1 uses standard Vue component definition (object-literal syntax). App2 uses class components (the actual component is a class that extends Vue by using vue-class-component package).

App1 works but in dev mode throws an error when loading the page about template compiler not being available. However, there is no error in production build.

App2 does not work at all - see error message in the console.

Example application

The example application allows the user to edit the template and then to use it with v-render-template. To start the example application run

$ npm start

and navigate to http://localhost:4000

To do the production build run:

$ npm run build

Pass data into template

<tr v-show="ajaxing == false" v-for="(item,index) in items">
   <template v-for="(action,index) in TableSettings.actions">
      <v-runtime-template :parent="item" :template="action.html"></v-runtime-template>
   </template>
</tr>

item is a object that contains an id such as:

{
'id': 321
}

action.html have:
<a class='text-white hover-info' :href="'Edit.aspx?id=' + _.get(this,'id')">Edit</a>

but _.get(this,'id') is undefine..

Cannot convert undefined or null to object

I'm getting a lot of cannot convert undefined or null to object-errors causing templates not to render.
I've tracked this down to the render function starting on line 34 in v-runtime-template.es.js.

The function calls Object.keys() for a couple of properties; the computed-properties-one is failing for me, because that is undefined instead of an object.

I've changed line 43:

var computed = $options.computed;

to

var computed = $options.computed || {};

which fixes it for me. Hopefully an object-check or fallback like this can make it into this plugin.

Feature Request: Pass props to the template

It'd be nice if we can pass specific props to the template - for example if you're looping through an object and each object needs to be passed in.

Since we can't just pass arbitrary props to the component, I'm proposing we pass in an object with the props, which then merges with the parent's data & props to be passed to the template.

Example:

<div v-for="person in people" :key="person.id">
  <v-runtime-template :template="fancy_name" :template_props="{name: person.name, id: person.id}"/>
</div>

Bug on building methods

Hi I think that there is a bug when we build passthrough methods.

Object.keys(methods).forEach(e => {if(typeof this.$options.methods[e]==="undefined") passthrough.methods[e] = methods[e];} );

We need to change into
Object.keys(methods).forEach(e => {if(typeof this.$options.methods==="undefined" || typeof this.$options.methods[e]==="undefined") passthrough.methods[e] = methods[e];} );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.