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.

1
  • Jeez. I'm sure I did that already. I must have had an unnoticed typo :-/
    – STWilson
    Commented Jun 12, 2017 at 19:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.