search

Home  >  Q&A  >  body text

vuejs, I want to print the parent's ID/name only once for its child

<td v-if="currentId != loop.id" class="text-center">
    <div :set="currentId = loop.id">{{ loop.id }}</div>
</td>
<td v-else></td>

Need to achieve this goal It is a multidimensional parent/child array and needs to be printed on a table. So when the first parent prints on a line, we stop printing duplicate parents until its children are finished. console warning I have set currentId as loop.id, it is showing console warning.

P粉478188786P粉478188786231 days ago410

reply all(1)I'll reply

  • P粉388945432

    P粉3889454322024-04-03 09:36:56

    data() {
      return {
        currentId: '0',
      }
    },
    methods: {
      assignCurrentId: function(id) {
        if( this.currentId == id) {
            return false;
        } else{
            Object.defineProperty(this, 'currentId', {value: id, writeable: false});
            return true;
        }
    }

    Found something here to stop/disable the reactivity of variables and it's working now - https://stackoverflow.com/a/52844620/5156910

    reply
    0
  • Cancelreply