0

computed vue js does not work with inertia I have a fresh installation of laravel with jetstream which uses inertia, and the computed properties do not work

computed: {
             compupares: function () {
                 var sum = Number (this.form.t33) + Number (this.form.t34);
                 this.form.pares = sum;
                 return sum;
                
             },
  • Can you add some more context/more information as to what exactly is not working? How are you using this computed property? I am successfully using computed properties with this stack... – Andrew Mar 29 '21 at 16:52

2 Answers2

0

As you can see in my second to last row I am modifying a variable this.form.pares = sum; the problem was that the computed properties cannot modify variables, they can only be displayed somewhere {{}} and when saving them, they can just be copied to that variable

0

If I am not mistaken your question, you try to set the value of an Inertia form property with a computed property. You should set the starting value to null in the form declaration and then change the value using onMounted:

First you create the computed property

let property_computed_value = computed(() => {
// your code here
})

Then initialize the form

let form = useForm({
 'final_value': '' 
});

and then

  onMounted(() => {
  form.final_value = property_computed_value
})