A comprehensive guide to resolving the [Vue warning]: props are required to be strings when utilizing array syntax

Here is my perspective :

<div class="col-md-8">
    ...
        <star :value="{{ $data['rating'] }}" :user="{{ $data['user_id']></star>
    ...
</div>

This is how my star component looks like :

<template>
    <span class="rating">
        <template v-for="item in items">
            <label class="radio-inline input-star" :class="{'is-selected': ((value >= item.value) && value != null), 'is-disabled': disabled}">
                <input type="radio" class="input-rating" name="input-rating" v-bind:value="item.value" v-model="value" :disabled="disabled" @click="rate(item.value)">
            </label>
        </template>
    </span>
</template>
<script>
    export default{
        props: [{'value': null,'disabled': Boolean}, 'user'], 
        data(){
            return{
                items: [
                    {value: 5},
                    {value: 4},
                    {value: 3},
                    {value: 2},
                    {value: 1}
                ],
                temp_value: null,
            }
        },
        methods:{
            rate: function (star) {
                var self = this;
                if (!this.disabled) {
                    this.$http.post(window.BaseUrl + '/star', {star: star}).then(function (response) {
                        console.log('submitted');
                    });
                    this.temp_value = star;
                    return this.value = star;
                }
            },
        }
    }
</script>

My CSS code follows this structure:

span.rating {
  direction: rtl;
  display: inline-block;
}

span.rating .input-star {
  background: url("../img/star.png") 0 -16px;
  padding-left: 0;
  margin-left: 0;
  width: 16px;
  height: 16px;
}

span.rating .input-star:hover, span.rating .input-star:hover ~ .input-star {
  background-position: 0 0;
}

span.rating .is-selected{
   background-position: 0 0;
}

span.rating .is-disabled{
   cursor: default;
}

span.rating .input-star .input-rating {
  display: none;
}

Upon clicking the star, I encounter errors in the console like so :

[Vue warn]: props must be strings when using array syntax.

[Vue warn]: Property or method "star" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in at C:\xampp\htdocs\myshop\resources\assets\js\components\Star.vue)

[Vue warn]: Property or method "disabled" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option. (found in at C:\xampp\htdocs\myshop\resources\assets\js\components\Star.vue)

What steps can I take to resolve these issues?

Answer №1

There appear to be multiple issues in the code you've shared.

Firstly, it seems unnecessary to use braces within props:

<star :value="{{ $data['rating'] }}" :user="{{ $data['user_id'] }}"></star>
         <!-- ^^ This line contains a syntax error -->

Instead, simplify it to:

<star :value="$data['rating']" :user="$data['user_id']"></star>

This can even be further streamlined to:

<star :value="rating" :user="user_id"></star>

Furthermore, there appears to be an issue with how props are declared, which is likely why Vue is unable to recognize disabled and value.

A simple way to declare props is:

props: ['value', 'disabled', 'user'],

If you need to add validations, refer to the documentation here: https://v2.vuejs.org/v2/guide/components.html#Prop-Validation

Another problem arises from directly mutating props.

<input ... v-model="value" ...>

Remember, value is a prop and should not be mutated by the component. Props should flow one way down. If you need to update the parent's value, consider using events. You can find more information on custom events here: https://v2.vuejs.org/v2/guide/components.html#Custom-Events

For further assistance, you may review my previous answer here: Update parent model from child component Vue

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

Concealing and revealing all dropdownlist elements using Asp.net javascript

Hey there, I'm working on an ASP.NET project and I have a dropdownlist that contains multiple items. I am looking to implement functionality where I can hide or show all the items in the dropdownlist based on user interaction. <asp:DropDownList id ...

Establishing and attaching a state in React Native

Currently, I am working on a timer application in React Native and aiming to display the elapsed milliseconds using state management. The guide I am referring to is slightly outdated as it uses plain JavaScript instead of ES6, so I took it upon myself to c ...

What is the best way to append an HTML element located by its ID to the body of a webpage

Is there a way to insert a DOM element with a specific ID into the body tag while clearing out all existing body nodes? The following approach doesn't seem to be effective: var elem = document.getElementById("email"); document.body.innerHTML = elem; ...

Creating custom dynamic components as needed

I've been stuck on this issue for hours without much progress... My goal is to develop a custom component that can be incorporated both via XML and programmatically. While adding the component through XML was quick and easy, I encountered several obs ...

Is there a way to automatically refresh the template whenever a scope variable is changed?

My goal is to have the showOrder.html template rendered when the value of orderHistory.type (a scope variable initialized as 'list') changes to 'show'. This change occurs when a link is clicked in the orderHistoryList.html. The model is ...

An issue arises when attempting to capture a screenshot with three.js, displaying the error message: "'modelViewMatrix' is a data that cannot be modified or configured."

Currently, I am utilizing three.js within my Vue application with the goal of capturing a screenshot of my scene as a blob. Initially, I tested this functionality by implementing: window.addEventListener('keydown', this.test.bind(this)); Within ...

"Troubleshooting: Mongoose uniqueness feature not functioning

I am encountering an issue with mongoose where 'unique:true' is not functioning as expected. Take a look at the schema I have formulated: var mongoose = require('mongoose'); var userSchema = mongoose.Schema({ username:{ type:St ...

Using Javascript to manage controls in three.js

I'm currently experimenting with creating a small game using three.js. Below is the JavaScript code responsible for controlling the game: window.onmouseover = function (ev) { down = true; sx = ev.clientX; sy = ev.clientY; }; window.onmous ...

The Paypal onApproved function is not triggering my save to Firebase operation as expected

After successfully processing a payment through PayPal integration API, I encountered an error while trying to save the subscriptionID to Firebase DB inside the onApproved method. Strangely, the firebase code works fine when executed in the created or moun ...

Tap on the hyperlink within the pop-up window

Having trouble clicking on a link from a popup. Once I click on the button, the popup appears for approximately 3 seconds: <toast-container class="ng-tns-c12-31 ng-star-inserted"> <div class="toast-top-center" id="toast-container" style="positio ...

The difference between calling a function in the window.onload and in the body of a

In this HTML code snippet, I am trying to display the Colorado state flag using a canvas. However, I noticed that in order for the flag to be drawn correctly, I had to move certain lines of code from the window.onload() function to the drawLogo() function. ...

Capable of generating an ajax URL parameter conditionally for utilization with jQuery Validate

I am having an issue with my jQuery validation script. What I am trying to achieve is this: when a user clicks the send button, the script will determine whether to execute an if or else statement based on the last portion of a string (isAdd). Subsequently ...

Error encountered while attempting to validate and add new entries

I am facing a challenge while attempting to insert a record into my mongodb database. Despite providing what seems to be the correct values, mongoose is flagging them as missing. Below is the Schema I am working with - var mongoose = require('mongoo ...

What are some ways to enhance the speed of swipe and scrolling on mobile devices using Javascript, CSS, and HTML?

Dealing with slow scrolling on iPhones has been a challenge for me. The application was developed using Vue.js. I was able to increase the scrolling speed on desktop using Javascript, but unfortunately, it doesn't translate well to mobile devices due ...

What is the method for determining the required or imported base path?

My package.json includes the main option to set the default file for importing like import 'my-index' from 'my-module' However, I would like to break up my-module into separate files so developers can include them individually with sta ...

Is there a way for me to choose multiple checkboxes simultaneously?

I have a dynamically created HTML table with checkboxes added for each row. $.each(data, function(id, value) { rows.push('<tr><td><input type="checkbox" autocomplete="off" class="chkbox" name="chkbox" value="'+value.site+' ...

The alteration of arrays within React.js

I've been working on this function: setNotActiveWalletsList = () => { const { GetAccounts } = this.props; let shallowCopyOfWalletsArray = [...GetAccounts]; const notActive = shallowCopyOfWalletsArray.filter(user => user.active != ...

retrieve the status of a checkbox in a dynamically generated element

I'm currently working on integrating the YouTube API into my app in order to display a dynamic list of cards. The cards are stored in a variable and then added to a playlist container using an each function. Each card contains a toggle switch for use ...

Leveraging Raycaster in Three.js to identify the children of ArrowHelper, specifically line and cone elements

I have successfully implemented a Raycaster for a basic painting application. This Raycaster is utilized for a "bucket tool" feature, allowing users to click on an object and change its color. While this functionality works seamlessly with geometry objects ...

The majority of my next.js website's content being indexed by Google consists of JSON and Javascript files

I’m facing an issue with Google indexing on Next.js (utilizing SSR). The challenge lies in ensuring that .HTML files are effectively indexed for SEO purposes. However, it seems that Googlebot predominantly indexes JSON and JavaScript files. To illustra ...