alexjoverm / v-runtime-template

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

Pass data into template #54

Closed gwumkt closed 5 years ago

gwumkt commented 5 years ago
<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..

neberaa commented 5 years ago

Why just not to use an <a> tag wihout v-runtime-template like these:

<tr v-show="ajaxing == false" v-for="(item,index) in items">
   <template v-for="(action,index) in TableSettings.actions">
      <a class='text-white hover-info' :href="`Edit.aspx?id=${item.id}`">Edit</a>
   </template>
</tr>
gwumkt commented 5 years ago

Because as i said, the a tag is coming from a variable action.html .. you can see that i have for loop on TableSettings.actions, every action can be diff thing.. it can be a tag or even a button or anything..

neberaa commented 5 years ago

What about using <div v-html="action.html"> with a :href above?

gwumkt commented 5 years ago

it will not work cause action.html contains item.id, and the v-html will not render that item.id..

gwumkt commented 5 years ago

ok guys i solved it by looking at the source code of that lib.

<v-runtime-template :template-props="{item}" :template="action.html"></v-runtime-template

im passing the item in the template-props so then the item is now accessible from the template