0

Using Vue 2, How do I bind to javascript in an html element attribute?

For example, I'd like to assign a colspan attribute dynamically to the javasript length property value of my data columns.

Instead of this:

<td colspan="4">

I want to do something like this:

<td :colspan="{ columns.length }">
1
  • 2
    You're almost there: <td :colspan="columns.length"> Commented Jun 12, 2017 at 19:29

1 Answer 1

3

Just don't need to specify brackets. Just do this:

<td :colspan="columns.length">

See the Vue documentation for Template Syntax.

Sign up to request clarification or add additional context in comments.

1 Comment

Jeez. I'm sure I did that already. I must have had an unnoticed typo :-/

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.