The Vue warning indicates that there was a failed type check for the "value" prop. It was expecting an array but received a number with a value of 1

I am facing an issue with an input of type number where I need to restrict the user from entering a number greater than ten. Initially, everything was working fine until I decided to change the value to an array (from value: 1 to value: [1, 1])

After switching to an array, I tried to set the first number in the array as the input value manually but encountered an error that I am struggling to resolve.

App.vue

<div>
    <customInput v-model="value[0]" :max-value="10" />
</div>

<script>
import customInput from "./components/HelloWorld";

export default {
name: "App",
data() {
return {
value: [1, 1],
};
},
components: {
customInput,
},
};
</script>

HelloWorld.vue

<div>
    <input :value="value[0]" type="number" @input="onInput" max="10" />
</div>

<script>
export default {
props: {
value: Array,
maxValue: Number,
},
methods: {
onInput(event) {
const newValue = parseInt(event.target.value);
const clampedValue = Math.min(newValue, this.maxValue);
this.$emit("input", clampedValue);
this.$forceUpdate();
},
},

};
</script>

The issue arose when I changed the value to an array. For reference, you can view my code on codesandbox.

Answer №1

While utilizing

<div>
     <customInput v-model="value[0]" :max-value="10" />
</div

In App.vue, a single value is being passed instead of an Array to HelloWorld.vue

You can either adjust the type of value in the component from Array to Number, or modify it to:

<div>
     <customInput v-model="value" :max-value="10" />
</div

Furthermore, in HelloWorld.vue, the input type is "number", so even if you pass the array to the component, a warning will be displayed.

Therefore, do you actually require an array to be transmitted to the children component?

P.S. In codesandbox, there's a missing parameter in this line:

const newValue = parseInt(event.target.value);
it needs to be:
const newValue = parseInt(event.target.value, 10);

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

Generate arrays with custom names by parsing JSON data

Currently, I am retrieving data from a MySQL database and converting it to JSON before passing it to a JavaScript class for chart display purposes. The challenge lies in creating arrays required by the chart from the JSON object without manually creating a ...

Encountering an issue with getDerivedStateFromProps in React where an error states: Unable to retrieve property 'setState' of null

Just found out that componentWillReceiveProps is deprecated and now we should be using the getDerivedStateFromProps lifecycle method. You can find more information about it at this link. This is how I'm implementing it: class Main extends Component ...

Quasar: construct in development mode

In my quasar.conf.js file, I have environmental settings set up like so: env: { API_URL: ctx.dev ? 'https://dev.apis.test.io/v2/' : 'https://apis.test.io/v2/' } When running the app locally, the development api is used. When ...

Ways to display JSON objects containing nested key-value pairs

In my JSON structure, each Mealplan includes a key and a corresponding value which is an object called meal. id: 1, mealsPerWeek: { Monday: { id: 4, name: "Burger", }, Tuesday: { id: 3, name: "Salad&qu ...

Why Changing the Width of a Flexbox Container Doesn't Impact Its Children?

Attempting to use TweenLite to animate the width of the blue sidebar down to zero, however facing an issue where the content breaks outside the parent's bounds. https://i.stack.imgur.com/4rEVr.png It is unusual for this to happen with Flexbox, given ...

Issue with Nuxt 3 Server-Side Rendering: Failure to Show Custom Error Page When Server API Endpoint Fails

I'm facing a challenge with my Nuxt 3 SSR application where the custom error page is not showing up when there's an error in a server API endpoint using createError. I've tried setting the fatal option to true or false but still end up seein ...

Exploring the world of jQuery waypoints and the art of modifying

This is only the second question I'm asking here, so please be gentle! I've been experimenting with jQuery waypoints to dynamically show and hide a border under my navigation menu based on scroll position. For instance, when the sticky nav is ov ...

Tips on updating v-for instantly?

What can be done if the product information of users can be changed by users, but the changes are not instantly reflected until the page is refreshed? <template> <div> <table> <thead> ...

Strategies for redirecting search queries when adding a new path

Issue I am facing a challenge with pushing a new path to the URI while maintaining existing search queries. For example: Current URL: https://example.com/foo?bar=123&foobar=123 When I use history.push('newPath'), I end up with https://exa ...

Is it expected to conceal children who are 2 years old?

I came across the following HTML code snippet: <ul id="product_create-header" class="stepy-header"> <li id="product_create-head-0" class="stepy-active"> <div>Categoría</div><span>Categoría</span> </ ...

Navigating with Angular 1.5 Component router in conjunction with Express.js

I'm currently working on an Express application and I am trying to capture all routes to redirect users to /public/app/index.html: app.all('/*', function (req, res, next) { // Let's just serve the index.html for other files to enab ...

guide on updating JQuery string with JavaScript to incorporate new parameters

Similar Question: How to replace only one parameter or fast with Jquery on Jquery String The website has a query string as follows: http://www.nonloso.html/?nome1=pollo&cognome1=chicken&nome2=a&cognome2=b&nome3=c&cognome3=d This ...

Transferring information from a method within a controller to a method within a directive using Angular

I am facing an issue in my Angular application where the data retrieved from an API is not being passed properly from a controller function to a directive function. Despite using .then() to ensure sequential execution, I still receive 'undefined' ...

Transferring an object from Javascript to C++/CX following a C++/CX interface in Windows Runtime Components

As a newcomer to Windows Runtime Component, I've been exploring ways to accomplish the following task. I'm looking to extend a C++ interface in JavaScript. namespace MySDK { public interface class LoggerPlugin { public: virt ...

### Setting Default String Values for Columns in TypeORM MigrationsDo you want to know how to

I'm working on setting the default value of a column to 'Canada/Eastern' and making it not nullable. This is the current setup for the column: queryRunner.addColumn('users', new TableColumn({ name: 'timezone_name', ...

How to Retrieve Correct JSON Data from Mongoose Query in Node.js

I am currently working on an express application that utilizes mongoDB as the database and handlebars as my server-side templating engine. Unlike many applications, I have chosen not to incorporate AngularJS or Ajax into my project. One of the challenges ...

Using React.JS: Display Object Map in rendering

I have an object with family information that looks like this: Family: Parent0: BirthPlace: "dsa" Birthday: "2021-01-04" Relationship: "dsa" SurnameAndName: "dasdsa" Parent1: BirthPlace: & ...

What are the reasons behind the lack of smooth functionality in the Bootstrap 4 slider?

My customized bootstrap4 slider is functional, but lacks smoothness when clicking on the "next" and "prev" buttons. The slider transitions suddenly instead of smoothly. Any suggestions on how to fix this? Here is the code for the slider: $('.carous ...

The authorization header for jwt is absent

Once the user is logged in, a jwt token is assigned to them. Then, my middleware attempts to validate the token by retrieving the authorization header, but it does not exist. When I try to display the request header by printing it out, it shows as undefine ...

Using JavaScript to access a button from a dropdown list in ASP.NET MVC

I'm trying to use a JavaScript function to trigger the click event of an HTML button when a drop-down list is changed. However, it seems like the correct id is not being found. @using (Ajax.BeginForm("GetReport", "Choices", new AjaxOptions() { ...