Practical tips for calculating attributes


Tips 1

We often encounter that the backend needs “start time” – “end time” (stored in two variables), but what! The component of the time selector we use can only bind onearrayAt this time, when we pass it to the back end, we need toarrayIt needs to be disassembled and then spliced together when echoing. The workload is small, but there is a lot of code and some variables. Is there a better way!!!

We putreceiveDateThis value becomesCalculation properties, and then useCalculation propertiesget/setWriting method

receiveDate: {
      get: function () {
        return this.form.rSTime && this.form.rETime ? [this.form.rSTime,this.form.rETime] : "";
      set: function (newVal) {
        let [rSTime, rETime] = newVal || [null, null];
        this.form.rSTime = rSTime;
        this.form.rETime = rETime;

If you need to verify here, you can directly verify only the first partrSTimeJust do it, and the verification method is the same

Tips 2

There will also be a situation in development, which can also be usedCalculation propertiesMore elegant solution

Limit or not: ● no ○ yes [input]

This kind of, the backstage often does not need thisBooleanValue, we need to define an additional variable (x) to receive. When switching options, we also need to add method settingsinputThe value of isSpecial value。 It is mainly necessary to judge whether there is a problem when echoinginputValue to determine whether the extra variable (x) needs to be set totrue, orfalse。 Is there a convenient way?

      return this.form.limit !== -1;
      this.form.limit = newVal ? '' : -1