What is the best way to save an object as a value for a radio input in Vue?

Looking to store values from an array of objects into radio inputs in Vue.js? Here's what I have:

const plans = [{type:'2'},{type:'3'},{type:'1'}]

I attempted the following approach:

<input type="radio" v-model="pick" :value="plans[0]" />
<input type="radio" v-model="pick" :value="plans[1]" />
<input type="radio" v-model="pick" :value="plans[2]" />

Unfortunately, this resulted in the error message:

Invalid prop: type check failed for prop "value". Expected String, Number, got Object

Do you have any suggestions on how to overcome this issue? Thanks!

Answer №1

If my understanding is correct, you can use the code snippet below:

const app = new Vue({
  el: "#demo",
  data: {
    selectedOption: null,
    items: [{value:'option1'}, {value:'option2'}, {value:'option3'}]
  }
})
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<div id="demo">
  <div v-for="item in items" :key="item.value">
    <input type="radio" v-model="selectedOption" :value="item" />
    <label for="">{{ item.value }}</label>
  </div>
  {{ selectedOption }}
</div>

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

Syntax error triggered and caught by ajaxError

I have implemented a client-side ajax error handler using the following code: $(document).ajaxError(processAjaxError); $.getJSON('/data.json'); In the server side, I have defined a function as shown below: def get(self): self.response.he ...

Getting your routing to function properly in React.js involves setting up routes for different

I have been working on a React project, which can be found here, and trying to tackle the issue of relative links in the navbar. However, every time I click on About Me, I encounter this message: Cannot GET /about The chunk of code I am currently dealing ...

Retrieve information from every nested array and present it in sequential order

I need to extract the index of each element in a nested array structure. For example, I have an array with 5 subarrays, each containing multiple elements. My goal is to retrieve the first element from each subarray, then the second element, and so on. Her ...

Tips for effectively handling numerous iterations of an identical NPM dependency

Situation I have been working on creating various D3.js charts using the latest version of D3 (4.9.1). However, I also need to incorporate occasional C3.js charts into my application, which poses a challenge as C3 requires D3 v3.5.0. Exploring Options ...

The Angular Material md-input-container consumes a significant amount of space

Currently, I am exploring a sample in Angular Material. It appears that the md-input-container tag is taking up a substantial amount of space by default. The output is shown below: https://i.sstatic.net/hQgpT.png However, I have come across the md-input- ...

Incorporating an image into a cell within a jqxgrid

I recently utilized Jqxgrid in a project where I was able to load data from a JSON string into the grid successfully. Now, I am looking to add images/icons in a column cell for each specific entry/row. Below is the code snippet that initializes the grid: ...

Is there a way to automatically start a YouTube video using JavaScript?

Is it possible to automatically play a YouTube embedded video after a visitor has been on the site for a certain amount of time, without affecting view count? I am looking for a JavaScript solution that can accomplish this without having to modify the em ...

Wordpress causing Jquery to malfunction; PHP function not executing

Looking to incorporate a script into my WordPress function.php file. Here's what I have so far: <?php function add_google_jquery() { if ( !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', ...

The code inside the if statement is somehow executing even when the if statement is not true

Similar Question: Issue with jQuery function running at inappropriate times I've spent several hours trying to figure out why my function isn't working properly. I have a function inside an if ($window.width() < 1000) statement, but it se ...

Incorporate a PHP variable into JavaScript

class Map { public $Id; public $longitudes; public $latitudes; public $lat_init; public $lng_init; public static function createMap($Id){ global $latitude, $longitude; $dbh = Database::connect(); $query = "SELECT * FROM `cartes` WHERE Id=? "; ...

Efficiently Managing Errors on REST Server

My application has the ability to generate a PDF on demand through service/generatePdf. The response includes content-type="application/pdf" with binary contents in the outputStream. According to business requirements, clicking a button should open a new ...

What is the best method for rotating segments in THREE.TubeGeometry?

I've successfully generated a flat tube structure using THREE.TubeGeometry with radiusSegments set to 2. However, once added to the scene, it appears perpendicular to the ground: https://i.sstatic.net/U3qTt.png Is there a way to rotate each segment ...

Rotate Chevron icon downwards on mobile devices in a Multilevel Dropdown Bootstrap 4

Bootstrap 4 is being utilized for my current project, I am looking to modify the rotation of the chevron icon in a multi-level dropdown menu specifically on mobile devices when the parent link is tapped, Here is the code snippet for the multi-level dropd ...

AngularJS routing with html5mode causing 404 error when using htaccess

I am currently working on my very first angularjs application using version 1.6x, and I am encountering some 404 errors with my router. Here is how my router is set up: app.config(function($routeProvider, $locationProvider) { $locationProvider.html5M ...

Authentication using SPA RSA 2048 encryption technology

For my current project involving Angular SPA development, the customer has requested the use of RSA 2048 for authentication. I'm uncertain about how the authentication token will be generated. My understanding is that the token should be created on th ...

jqGrid - Error when the length of colNames and colModel do not match!

Whenever I implement the code below, it triggers an error saying "Length of colNames and <> colModel!" However, if isUserGlobal is false, no errors occur. The version of jqGrid being used is 4.5.4 receivedColModel.push({name:'NAME', index: ...

The setInterval function in JavaScript fails to update the result

I have successfully implemented a countdown function that is working as expected. // Set the date we're counting down to var countDownDate = new Date("<?= $stop_datejs ?>"); // Update the count down every 1 second var x ...

Issue encountered while invoking a jQuery function with JavaScript

I encountered an error on the line: validate(); When attempting to execute the following jQuery function: (function ($) { "use strict"; var methods = { validate: function () { if ($(this).is("form")) ...

Is there a way to use Selenium to automate the clicking of two buttons with empty href attributes? Each button has a function name and arguments within the href

Here is the HTML code for both buttons: <td> <a href="javascript:abcMy(2310);" class="btn btn-lawa btn-primary btn-primary-lawa">View</a> </td> <td> <a href="javascript:abcMy(2330);" class="btn btn-lawa btn-primary btn ...

Obtaining chargePermissionId in Amazon Pay Integration without the need to capture or create chargeId

I am currently in the process of integrating Amazon Pay into my Vue.js storefront. As I attempt to place an order, the Magento2 Amazon Pay module is requiring a Session ID and chargePermissionId to capture the amount. When authorizing through the Amazon ...