rdunk / sanity-blocks-vue-component

[DEPRECATED] Vue component for rendering block content from Sanity
MIT License
71 stars 10 forks source link

Access ordinal position within blocks array #20

Closed ajrowland closed 3 years ago

ajrowland commented 3 years ago

More a question than an issue. Is there a way of determining the position of a component within the blocks array?

Use case would be to apply a class to a component's outer element if it's the first item in the parent blocks array.

I guess I could use:

this.$parent.blocks.findIndex(block => block._key == $attrs._key)

Is there a better option?

rdunk commented 3 years ago

Hmm, no obvious solution comes to mind that is specific to this package. Could you do something like map your blocks array and conditionally augment the attributes that are passed as props?

An example and version you're working with would be helpful.

ajrowland commented 3 years ago

This was recommended by a fellow dev, thanks. We went with the solution in my original comment.