"Why is it that the selected option doesn't seem to be functioning properly with v-model

I am aware that the selected attribute does not function when utilizing v-model. However, I need to use v-model to retrieve the selected user and incorporate it into my firebase. Therefore, here is how my HTML is structured:

<select v-model="medespeler1" class="inputbox rounded" required>
  <option v-for="(option, i) in medespelers" :key="i" :selected="selected">{{ medespelers[i] }}</option>
</select>

To access all the medespelers stored in the database along with the medespeler1 value, I have included this in the data property:

data: function() {
  return {
    medespelers:[],
    medespeler1: '',
  }
},

Within Firebase, I save all the medespelers in an array and pass it to the data property. Since I must send the medespeler1 value as well, using :selected is not feasible. Where should I begin to ensure that both the medespeler1 value is stored and there is a selected item within the array?

Answer №1

To make the <select> react to the value of medespeler1, simply set the value of medespeler1 in the Vue data:

new Vue({
  el: "#app",
  data() {
    return {
      medespeler1: "apple"
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <select v-model="medespeler1">
     <option>apple</option>
     <option>banana</option>
     <option>cherry</option>
  </select>
  
  Selected: {{ medespeler1 }}
</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

How to install Typed.js without using Node.js

I'm currently working on a project that requires the JavaScript library typed.js, however, I am using the free webhost 000webhost which does not support Node.js. Since typed.js is typically installed using Yarn, NPM, or Bower - all of which require No ...

`Is there a way to avoid extra re-renders caused by parameters in NextJS?`

I am currently in the process of implementing a standard loading strategy for NextJS applications using framer-motion. function MyApp({ Component, pageProps, router }) { const [isFirstMount, setIsFirstMount] = useState(true); useEffect(() => { ...

"The issue with the attribute updating functionality in Meteor and MongoDB needs to be addressed

I have run into an issue while trying to update a document with the click of a button. Every time I attempt to update it, an "Internal error" message pops up. The document I am working with is called "confirmed" and it has the capability to store true/fals ...

Could the autofill feature in Chrome be turned off specifically for Angular form fields?

Even after attempting to prevent autofill with autocomplete=false and autocomplete=off, the Chrome autofill data persists. Is there a method to disable autofill in Angular forms specifically? Would greatly appreciate any recommendations. Thank you. ...

The submission is processed regardless in Firefox

var form0 = document.forms[0]; form0.onsubmit = function(e){ alert("form submitted"); var email = form0.elements["email"].value; var url = "https://bpi.briteverify.com/emails.json?address="+email+"&apikey=my-key&callback=emailResult"; ...

The WordPress site you are trying to access does not have the 'Access-Control-Allow-Origin' header included in the requested resource

I am currently facing an issue with my MVC application where I am using jQuery .get() to fetch data from our company's Wordpress site to display on a page. Surprisingly, this functionality works fine in IE 11 but fails in Chrome and Edge browsers. Be ...

Expansive menu that stretches the full height of the webpage

I'm having difficulty making my side spry menu extend the full length of the webpage. I tried using this code: $("nav").css({ "height" : $("nav").height() }); but it still isn't working as expected. I just want the grey color, like ...

Issue: TableHead inside an Expandable Row in MUI-Datatable is being duplicated for each row, causing the table to not be centered.Explanation: The

Can anyone help me with this issue? I'm having trouble with my table where the headings are repeating for every row and the table is stuck on the far right side. How can I center the table instead? https://i.sstatic.net/y7Cs5.png Codesandbox: https: ...

JavaScript does not acknowledge that one variable is greater than or equal to another

My issue lies in the fact that my code recognizes that 100 is less than 2000, but fails to recognize that 200 is less than 1000. Below is my code snippet (I am also using jQuery as a framework): $('.filter-price').submit(function(e) { var ...

Trigger the mousemove event only after the mouse click event has been activated

I need help with my code. I want an onmousemove event to occur when I click and move the mouse. Can someone assist me please? </head> <body> <img id="myImgId" alt="" src="Chrysa ...

The initial res.body object in NodeJS is enclosed in quotation marks

I've hit a roadblock while working on my social media website project using the MERN stack. Despite scouring the internet, I haven't been able to find a solution to the issue at hand. While following an online course, I encountered a problem tha ...

Tips for arranging various information into a unified column within an Antd Table

Is there a way to display multiple data elements in a single cell of an Ant Design table, as it currently only allows insertion of one data element? I am attempting to combine both the 'transactionType' and 'sourceNo' into a single cell ...

Generate a fresh array by evaluating the differences between two arrays of objects

Imagine having two arrays of objects like this: let oldBookDetails = [ {'name':'Harry pottar','amount':10, is_modified: false}, {'name':'LOTR','amount':20, is_modified: false}, {' ...

Synchronizing Data between Elasticsearch and MongoDB to Retrieve Query Results

I'm currently working on a project that involves integrating Elasticsearch with our existing Mongo data source. The team has decided not to use river due to lack of support, and instead, they plan on running a cron job to update all the records in Ela ...

Building objects with attributes using constructor functions

My question pertains to JavaScript constructor function prototypes. Suppose I have code like the following: a = function (name){this.name = name}; a['b'] = function (age){this.age = age}; c = new a('John'); c.a['b'](30); Is ...

How can you efficiently identify and resolve coding errors or typos in your code?

While practicing node.js and express.js, I encountered an issue with finding typos. One such instance was when I mistakenly typed: const decoded = jwt.veryfy(token, config.get('jwtSecret')); instead of jwt.verify. Even though I eventually disc ...

Enumerated type alias in Typescript

Within my typings file, I have the following: declare namespace Somatic { enum PropType { html, object, css } } In a separate file named index.ts, I create a shorter alias for this enum like so: type PropType = Somatic.Pr ...

Select only the desired time option from the Datetime-picker in AngularJS

I am working with AngularJS and I need to split a datetime-picker into two separate parts. Normally, when you open the calendar, you first select the day and then the time (hours and minutes). My goal is to have two different datetime-pickers - one for sel ...

Learn how to retrieve data by clicking on the previous and next buttons in FullCalendar using Vue.js

Seeking guidance on retrieving calendar data from the database for my Vue frontend, I have incorporated the fullcalendar API. Successfully able to retrieve data for the current week, however facing challenges when attempting to fetch data for the previous ...

Error message 'Module not found' occurred when trying to incorporate Axios library into project

Hey there! I am encountering a similar issue as described in this post ('Module not found' babel error after installing axios). Despite trying all the recommended solutions, the error continues to persist: Failed to compile ./src/apis/youtube. ...