1

I have 3 desks in a table having role_id 2, 4 and 6. I have two tables. I want to display a different role name on a button based on the current user's role_id.

I want to display:

  • the role name having role_id 4 if the current user_role_id = 2
  • the role name having role_id 6 if the current user_role_id = 4.

user table enter image description here

registration table enter image description here

code

<span v-if="user.user_role_id ==results.desk_user_role_id">
    <v-btn small color="primary"  v-on:click="getNextDesk" style="width:400px;">Forward to </v-btn>
    <v-btn small color="primary" v-on:click="getPreviousDesk" style="width:400px;">Revert </v-btn>
</span>

Script code

getNextDesk(currentdeskid) {
  if (currentdeskid === 2) {
    return 'Technical Desk';
  }
  if (currentdeskid === 4) {
    return 'Executive Desk';
  }
  return '';
},
getPreviousDesk(currentdeskid) {
  if (currentdeskid === 6) {
    return 'Technical Desk';
  }
  if (currentdeskid === 4) {
    return 'Registration Desk';
  }
  return '';
},
2
  • Are you just trying to change the button name on click? Commented Apr 17, 2020 at 14:26
  • Actually I have 3 user for now i.e registration, technical and executive. Registration will forward record to technical. So, when registration login, button with forward to technical should be displayed in home page, when technical login, button with forward to executive should be displayed in home page and so on. @Dan Commented Apr 17, 2020 at 15:00

1 Answer 1

1

This is my best guess about what you're trying to do:

new Vue({
  el: "#app",
  data() {
    return {
      user: { user_role_id: 2 },
      roles: {
        2: { name: 'Registration', next: 4 },
        4: { name: 'Technical', next: 6, previous: 2 },
        6: { name: 'Executive', previous: 4 }
      }
    }
  },
  computed: {
    forwardTo() {
      const { next } = this.roles[this.user.user_role_id];
      return next ? 'Forward to ' + this.roles[next].name : false;
    },
    revertTo() {
      const { previous } = this.roles[this.user.user_role_id];
      return previous ? 'Revert to ' + this.roles[previous].name : false;
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div>
  User:
  <select v-model="user.user_role_id">
    <option v-for="(role, id) in roles" :value="id">{{ role.name }}</option>
  </select>
  </div><br />
  
  <button v-show="forwardTo">{{ forwardTo }}</button>
  <button v-show="revertTo">{{ revertTo }}</button>
</div>

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

11 Comments

I will try it. Thank you. @Dan
I got 'name' is assigned a value but never used . 'previous' is assigned a value but never used 'name' is assigned a value but never used 'previous' is assigned a value but never used. @Dan
Those are just lint warnings, not an actual error... I updated the code anyway.
I need to call v-on:click on same button for vue.js axios post method. Can I call both v-show and v-on:click on same button?
Yes sure, try it out: <button v-show="forwardTo" @click="myMethod">
|

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.