Can mock.js associate the values of two attributes?

at present, when I am working on a vue project using json-server + mock.js, when I look at the data returned by the interface before the back-end students, I find that there is a paragraph like this:

role:0, // 01
roleValue: "" // 

if I use mock.js to simulate data, how can I make these two values correspond one to one without an array, consistent with the interface written at the back end? (the value of roleValue is displayed when it is displayed, and the parameter passed in when modified is role, but the value of roleValue will be modified accordingly.) if mock.js cannot implement this method, is there any other solution? Look forward to your help very much!

Mar.02,2021

I also need this


although I don't know much about it, I don't know whether to provide a general idea

var r = {};
r[role] =  roleValue;
console.log(r.0);

We used rap2 to manage instead of messing with Mock.js directly.
then, you can directly set roleValue to type "function", and then set its "initial value" to something similar to the following code:

function() { 
  return (this.role === 0 ? '' : '');
}

you can see that inside the function, this can correspond to other key of the current simulation.
I hope I can help you.

you can't map in comments, but you can do this in rap2:

clipboard.png


let roleVals=['','']

roleValue=roleVals[role]

I've been using json-server + mock. You can use dependency functions to write this

.
{  
  // 
  'role': '@PICK([0, 1])',
  'roleValue': function() {
    // role
    let role = this.role
    return role === 0 ? '': ''
  }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf74eb-3204e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf74eb-3204e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?