0

I have the following code in vue-js:

    <table class="table table-sm user-perm-list">
      <tbody v-for="index in totalUsers" v-bind:key="index">
        <tr>
          <td>
            <div class="text-medium">{{userPermissionsName[index-1]}} </div>
            <div class="d-flex py-1">
              <a 
                 style="cursor:pointer; margin-right:0.4rem" 
                 @click=userPermissionsDownloadClicked(index-1) 
                 :title="userPermissionsDownload[index-1] ? 'Download Permitted':'Download not permitted'"
                 v-bind:class="[userPermissionsDownload[index-1] ? 'permission-icon-class-active' : 'permission-icon-class-inactive']">
                <downloadPermissionIcon/>
              </a>
            </div>
          </td>
        </tr>
      </tbody>
    </table>

the v-bind:class inside "a" tag is not working. Inside userPermissionsDownloadClicked, I am toggling the variable: userPermissionsDownload[index-1]. It works with a non array variable but not working with array variable

4
  • Can you post the data you have for your totalUsers variable? Commented Nov 15, 2019 at 15:44
  • Do you mean to have a new <tbody> for every element in totalUsers? I would expect the v-for directive to exist on the <tr> element in this case. Commented Nov 15, 2019 at 15:51
  • Can you show an example of an object in the userPermissionsName array? That along with the totalUsers variable will help us know where the problem lies Commented Nov 15, 2019 at 15:55
  • Is the title updating correctly? Commented Nov 15, 2019 at 17:47

1 Answer 1

3

This is one of the "Vue Gotchas"

https://vuejs.org/2016/02/06/common-gotchas/

From "Why isn’t the DOM updating?"

When you modify an Array by directly setting an index (e.g. arr[0] = val) or modifying its length property. Similarly, Vue.js cannot pickup these changes. Always modify arrays by using an Array instance method, or replacing it entirely. Vue provides a convenience method arr.$set(index, value) which is syntax sugar for arr.splice(index, 1, value).

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.