Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs append data-attribute conditionally

I try to add conditionally a data attribute value to my vue list on loop and I try the following

<ul data-parent="{{model.parent_id !== null ? model.parent_id : 0}}"></ul>

but in this case the list do not renders anymore, if dump out outside html tag {{model.parent_id !== null ? model.parent_id : 0}} than I see the correct output

like image 438
fefe Avatar asked Dec 23 '22 14:12

fefe


1 Answers

Use : before that and I would create a computed property like this.

computed: {
     parentId() {
       if (this.model.parent_id !== null)
          return this.model.parent_id
       return 0;
     }

}

<ul :data-parent="parentId"></ul>
like image 155
Georgi Antonov Avatar answered Jan 10 '23 19:01

Georgi Antonov