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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With