Error: Unable to set value on Vuejs key - the target is read-only

Currently, I am utilizing a combination of Laravel9 with Vuejs3. In one of my blade views, I pass PHP variables to a Vue component like so:

<subscription-form 
location="{{ $props['location'] }}"
orientation="{{ $props['orientation'] }}"
/>

Within the main Vue file where I receive this data, my script setup looks something like this:

const initProps = defineProps(['location', 'orientation']);

const values = reactive(initProps);

This parent Vue calls a child component using the following code:

<component 
          v-bind:is="steps[step]"
          v-bind:formValues="values"
></component>

The issue I'm facing is that I cannot write to the reactive variable values in my child Vues. This results in an error message stating:

[Vue warn] Set operation on key "location" failed: target is readonly.

This problem arises when attempting to modify the value as follows:

props.formValues.location = location;

Prior to passing PHP variables from the blade to the parent Vue, everything was functioning correctly. However, now that data props are being passed through two levels (from blade to main Vue, and then from main Vue to child components), it seems to be read-only.

I have attempted switching the initProps and values variables from const type to var, but unfortunately, this did not resolve the issue.

If anyone has experienced a similar situation or has any insights, your help would be greatly appreciated!

Answer №1

Feeling let down... My defineProps() function was returning undefined, causing a malfunction The culprit turned out to be: THE USE OF CAPITAL LETTERS! I updated

<subscription-form :initPropsValues="{{ json_encode($props) }}"/>
to
<subscription-form :initprops="{{ json_encode($props) }}"/>
And now my defineProps() is returning the correct object! Why do uppercase letters cause this issue?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the intricacies of Sails Js and Vue.js communication

Currently, I am delving into both Sails and Vue.js by developing a comprehensive REST application. Up to this point, I have successfully created a multi-step sign-up page using Vue that POSTs all necessary information to different Controllers in Sails, co ...

Is it feasible to activate a Bootstrap Tooltip from a different element?

I am currently developing a system that enables users to add notes over an image they upload. Presently, I have a note div that, upon clicking, opens a text box for editing. When hovering over this div, I utilize Bootstrap Tooltip to preview the contents o ...

The Vue template syntax utilizes double curly braces for incrementing values within must

Embarked on learning Vue.js recently and I am intrigued by the unusual behavior in my simple code. I cannot seem to figure out what is going wrong. I am attempting to increment a counter inside mustache syntax, but something strange is happening with this ...

List component in Angular not refreshing after sorting the array in the service

Currently, I am delving into the realm of Angular (version 5+) to enhance my skills by working on a small project. The project involves setting up basic routing functionalities to showcase the ContactList component upon selecting a navigation tab. Addition ...

How to implement jquery select functionality on clickable table rows?

I've come across a challenge while trying to implement clickable table rows with the jquery selectable function. Everything works perfectly fine with li elements, but I seem to hit a roadblock when using tables - the click event just stops working. Wh ...

Dynamically resolve Vue component names as needed

Looking for a solution to dynamically resolve Vue (sfc) component names on the fly. My scenario involves obtaining component names from a backend and needing to convert them into actual component names on the frontend. For example: <text/> => /co ...

Is it possible to swap out one ID value for another using JavaScript?

I am facing two issues 1) First Issue I need to update the current id value with a new one. Whenever the a tag is clicked, an event in jQuery code should be triggered to change the id value. For example, When a button is clicked <div class="video" i ...

How can I trigger a PHP function from within an HTML onClick() event?

While I have come across a response on stackoverflow regarding form submission, my query pertains to a different implementation. I am in need of calling a function that registers a variable in $_SESSION[], and then redirects to another page (html/php). I ...

Leaflet Three.js integration

Currently, I am working on creating an overlay layer for Leaflet that will showcase 3D content such as buildings. However, I have encountered difficulties in ensuring that movements on the Leaflet map are synchronized with those in the overlay scene. At t ...

Changing the position of the icon in the bootstrap validator

I'm currently attempting to validate form fields in a web project. The goal is to achieve a specific result, similar to the image below: https://i.stack.imgur.com/EVeJf.png While I have made progress with a simple solution that almost meets the requi ...

Here is the process to make a GET request to an API with input parameters using JQuery and JavaScript in an Asp.net view when a particular tag

Seeking assistance in displaying the count of orders on my view using a special tag. I have written a stored procedure in SQL that returns the order count based on the input type. To showcase all types of orders, I have designed multiple boxes on my form. ...

The v-data-table-server is failing to refresh the component within the table template

I am utilizing a Vuetify v-data-table-server (docs) that dynamically updates itself by fetching data from an API. <template> <v-data-table-server v-if="events.length > 0" v-model:items-per-page="events_limit" : ...

Passing "this" to the context provider value in React

While experimenting with the useContext in a class component, I decided to create a basic React (Next.js) application. The app consists of a single button that invokes a function in the context to update the state and trigger a re-render of the home compon ...

Unable to display the value of my array in JSON encoded PHP due to it being undefined

In my cart.php file, I have encoded an array to JSON and returned it to an AJAX function: $data = array(); $data['total'] = '10000'; $data['quantity'] = '10'; echo json_encode($data); In my index.php f ...

Effects with Cleanup - terminates ongoing API calls during cleanup process

Developing a React album viewing application: The goal is to create a React app that allows users to view albums. The interface should display a list of users on the left side and, upon selecting a user, show a list of albums owned by that user on the righ ...

Custom input field in Material UI not communicating properly with Redux form

I am currently utilizing Material UI and React to implement a custom input field. While using redux form for form validation, I have encountered an issue where the onBlur and onFocus events are not being dispatched successfully. Interestingly, if I switch ...

Adding substantial sections of HTML without any adjustments

While I am working on DOM manipulation, I have encountered the need to insert large blocks of HTML. I am looking for a more efficient way to do this rather than relying on concatenation or creating a messy code structure. Consider the simple code snippet b ...

What is the best method for inserting the HTML content from a specific div into a textarea?

Everything seems to be working fine, but once I insert the HTML into the textarea, an issue arises where the div gets wrapped within another div, causing the layout to break. var urls = []; $('body').on('click', '.btn_video&apos ...

JavaScript Filter Function: filtering based on multiple conditions (either one can evaluate to true)

I seem to be missing something very simple here. I am working with an array of objects that contains various information. Depending on user interaction, I want to filter out certain objects; let arr = [ {'num': 1, 'name': 'joe&a ...

Modifying subtotal values using PHP and JavaScript

I've been working on this code snippet to calculate my subtotal and determine the total payment. Can someone provide some assistance? $viewx = mysql_query("select distinct toorderid from ordercontainer where toordercategory='$ordercategory' ...