Closed envomer closed 8 years ago
This should be addressed in 2.1 via "template slots" - basically, a slot element that serves as a template that will be given data from the child component. Similar to passing a render function down instead of passing down already-rendered elements.
I'll open an issue discussing this feature in details when we start working on it.
@envomer
// inside v-for="column in columns"
<partial v-if="column.html" :name="column.html"></partial>
<span v-else>...</span>
new Vue({
...
data () {
return {
columns: [
...
{ key: 'opt', title: 'Options', html: 'my-html' }
]
}
},
partials: {
'my-html': '<button @click="editItem(XXX)">Edit</button>'
},
methods: {
editItem(xxx) { ... }
}
})
@kenberkeley partials have been deprecated in vue2, haven't they?
https://vuejs.org/v2/guide/migration.html#Vue-partial-removed
@envomer so just use slot or dynamic component instead, for vue 1
Any updates to this issue? @envomer - Have you solved this problem? I'm also trying to implement Datatables on vue 2.
In Vue 1.x all I had to do is recompile the Datatable DOM inside the Datatable's drawCallback() function to make my action buttons work:
...
$('#datatable').dataTable({
...
drawCallback: function (settings) {
var $element = $('#app-datatable');
vm.$compile($element.get(0));
},
...
});
But it does not work any more because the "$compile" has been removed.
@chrislandeza try dynamic component instead, demo' s here
what is the solution?
@Ucdit the answer is called 'scoped slots' see: https://vuejs.org/v2/guide/components.html#Scoped-Slots
e.g Child component:
<div class="child">
<slot text="hello from child"></slot>
</div>
Parent component:
<div class="parent">
<child>
<template scope="props">
<span>hello from parent</span>
<span>{{ props.text }}</span>
</template>
</child>
</div>
Result:
<div class="parent">
<div class="child">
<span>hello from parent</span>
<span>hello from child</span>
</div>
</div>
@chrislandeza Have you solved this problem?
I have a datatable component and i am using it on many different components/pages with different data. i just pass an object with the columns and it renders it. and some datatables have action buttons (edit, delete), some don't. and each of the action button should trigger a function on the component it was called on.
Here's the code. https://jsfiddle.net/hwk7bLhf/4/
It would be cool to be if i was able to somehow compile the 'html' content given in the columns object and use the vue provided elements and directives/plugins/mixins, etc....
I tried turning the column definition into components but i am not sure if it's a good idea to define global components for every column that has a html field with vue logic in it.
In vue 1 I used partials that handled this problem very well, but now with vue2 it's gotten a little harder :P
Do any of you guys have idea or can think of a way to solve this problem?
There are also other people wondering if it's possible: http://forum.vuejs.org/t/on-vue2-0-i-should-be-how-to-dynamic-compile-the-template-and-binding-template-events/117 http://forum.vuejs.org/t/vue-js-1-x-this-compile-equivalen-vue-js-2-x-please/515 http://forum.vuejs.org/t/vue-2-0-dynamic-event-handling/916/2