Reputation: 830
I am trying to think of a way to add more than one attribute dynamically. Below is a mockup code for that. If I loop through attributes and try to add it to img tag then I'll have more than one image tag and that I don't want. I want to have all the attributes inside the array to be on the same element.
Any help would be appreciated.
<template>
<img />
</template>
<script>
export default {
data(){
attributes: [
{class: 'main'},
{src: '/somthing/img.jpg'}
]
}
}
</script>
Upvotes: 0
Views: 557
Reputation: 864
You can use v-bind for that purpose. Example:
<template>
<img v-bind="attributes"/>
</template>
<script>
export default {
data(){
return {
attributes: {
class: 'main',
src: '/somthing/img.jpg'
}
}
}
}
</script>
If you would like to also dynamicly bind event's listeners you could use v-on
same way as I did with v-bind
Upvotes: 1