Loss of mutable responsiveness in Composition API
P粉141925181
P粉141925181 2023-09-16 22:54:36
0
1
538

I'm trying to get the ranks array of ranks_options from the useForm helper but it can't keep track of the current array

Please check below is my code

const form = useForm({
    name: null,
    ranks: [],
});

function addRanks() {
    form.ranks.push({ name: null, id:null});
}

ranks_options = form.ranks.map(function (value) {
    return value.name;
});

P粉141925181
P粉141925181

reply all(1)
P粉523335026

Convert it to a computed property :

const ranks_options = computed(() => form.ranks.map(value => value.name)

This will set form.rank as a dependency and recalculate its value when the dependency changes.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!