0

How does one set attributes on Vue.js tag nodes (VNode) programmatically without a need to define vnode.data and vnode.data.attrs each time?

The way I use is far from optimal:

const itemNode = h('div', item.title)
itemNode.data = {}
itemNode.data.attrs = {}
itemNode.data.attrs.class = 'some-class'

1 Answer 1

2

Figured out with The Data Object In-Depth

const menuItemNode = h(
  'div',
  {
    class: {
      'some-good-class': true,
      'some-bad-class': false
    }
  },
  item.title
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.