An attribute in data in vue depends on the result of computed calculation

wants to handle some business logic in computed, but ESlint prompts that variables in data cannot be reassigned in computed; is there a better way for
to handle it? Except for putting it in watch

    computed: {
        userData() {
            const userData = JSON.parse(JSON.stringify(this.data));
            let resultArr = [];

            Object.entries(userData).forEach(([key, value]) => {
                // eslint-disable-next-line
                userData[key].isFull = this.checkListItem(userData[key]);
                userData[key].showName = this.nameFormat(userData[key]);
                ...
                resultArr.push(userData[key]);
            });

            // 
            _.forEach(resultArr, (item, index) => {
                _.forEach(this.defaultPerson, (it, id) => {
                    if (it === item.ads && !item.isFull) {
                        // eslint-disable-next-line
                        this.isSelected.splice(index, 1, false);
                        // eslint-disable-next-line
                        this.addPeopleArr.splice(index, 1, false);
                    }
                });
            });

            return resultArr;
        },
    },
Apr.29,2022

this depends on your specific needs. If you want to change the value of other attributes under this value change, it is best to use watch. If you only want to implement this change once, you can consider dealing with the current requirements of
during mounted. My suggestion is to put


computed to set the
ide/computed.html-sharp%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7%E7%9A%84-setter" rel=" nofollow noreferrer "> calculation property of setter


watch is to listen for event changes caused by a value change. Computed is the result of monitoring multiple value changes, depending on your business scenario

Menu