0

I get into a problem. Here's my code:

<md-table-cell
  :style="arrDisplay[1][i1+3] > 0 ? {background: 'orange'}: ''"
  colspan="3"
  v-for="(m1, i1) in 2"
  :key="i1"
>
  <div
    contenteditable
    v-text="arrDisplay[1][i1+3] > 0 ? arrDisplay[1][i1+3] : ''"
    @blur="onEdit(1, i1+3)"
  ></div>
  <div class="del" v-if="arrDisplay[1][i1+3] > 0">
    <md-icon>clear</md-icon>
  </div>
</md-table-cell>

I want the table cell have orange background when it's value > 0 else white. It work perfectly fine after calculate arrayDisplay but not when I edit it:

onEdit(y, x) {
  var src = event.target.innerText
  this.arrDisplay[y][x] = parseInt(src)
},

But if I edit it by Vue DeveloperTools it works. I think if I'm right the reason maybe Vue does not recognize that I change arrDisplay but have no idea how to fix it. What should I do ?

1
  • simplest thing would be to make the style a computed property Commented May 5, 2020 at 9:47

1 Answer 1

1

You are trying to update an item using an index in an array.

As explained here this is not reactive. That's why you don't see the update.

Try this:

Vue.set(this.arrDisplay[y], x, parseInt(src))

Note: make sure that this.arraDisplay[y] is reactive. If it is not, then you need to use Vue.set when creating it also.

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.