Home  >  Q&A  >  body text

Vuejs set operation on key failed: target is read-only

<p>I use Laravel9 and Vuejs3. I have a blade view that passes a php variable to a vue component: </p> <pre class="brush:php;toolbar:false;"><subscription-form location="{{ $props['location'] }}" orientation="{{ $props['orientation'] }}" /></pre> <p>In the main vue where I receive the data, I have the following code in the script settings: </p> <pre class="brush:php;toolbar:false;">const initProps = defineProps(['location', 'orientation']); const values ​​= reactive(initProps);</pre> <p>This parent vue calls a component like this: </p> <pre class="brush:php;toolbar:false;"><component v-bind:is="steps[step]" v-bind:formValues="values" ></component></pre> <p>The problem is that my reactive variable <code>values</code> cannot be written in my child vue. I got an error</p> <pre class="brush:php;toolbar:false;">[Vue warn] Set operation on key "location" failed: target is readonly.</pre> <p>This happens when I do: </p> <pre class="brush:php;toolbar:false;">props.formValues.location = location;</pre> <p>It works when I don't have to pass php variables from blade to parent vue. But now I have two levels of data props, from the blade to the main vue and then from the main vue to the subcomponent and it's read only. </p> <p>Help! </p> <p>I tried switching the <code>initProps</code> or <code>values</code> variables from const type to var but it didn't do anything. </p>
P粉785905797P粉785905797420 days ago526

reply all(1)I'll reply

  • P粉481815897

    P粉4818158972023-08-27 09:17:54

    I am disappointed... This doesn't work because my DefineProps() returns undefined The problem is: capital letters! I changed arrive My DefineProps() returns my object! Why doesn't this work with uppercase letters?

    reply
    0
  • Cancelreply