[Vuejs]-Object element call function in Vuejs

2👍

You can use help of v-html, which takes care of rendering of html in the views. In the HTML, you can call the function like this:

<tr v-for="entry in tableData">
  <td v-for="(value, key) in columns" v-html="value.content(entry)">
  </td>
</tr>

To make this work I have modified columns data as well, as both elements need to have content.

   columns: {
      name: {
        title: "name"        ,
        content: function(entry) {
          return "<span>" + entry.name + "</span>";
        }
      },
      status: {
        title: "status",
        content: function(entry) {
          return "<strong>" + entry.status + "</strong>";
        }
      }

Whole working code is here.

Leave a comment