简体   繁体   English

如何将 Vue 中选定的表单选项保存到 Firebase

[英]How Can I Save Selected Form Option in Vue to Firebase

I have a collection that I want the option selected by the user submitted to in firebase.我有一个集合,我希望用户在 firebase 中提交选择的选项。

<select v-model="selected">
<option disabled value="">Marital Status</option>
<option>Married</option>
<option>Single</option>
<option>Divorced</option>
<option>Widow</option>
</select>

When I bind the form select with profile.maritalStatus, the option selected will be submitted to profile collection in firebase, but the placeholder on the select form won't show on the page.当我将表单选择与 profile.maritalStatus 绑定时,选择的选项将提交到 firebase 中的配置文件集合,但选择表单上的占位符不会显示在页面上。 How can I bind with v-model="selected" and be able to submit it to the profile collection.如何与 v-model="selected" 绑定并能够将其提交到配置文件集合。

data (){
selected:"",
profile:{
maritalStatus: null,
age: null, 
profession: null,
}
},

methods:{
Save(){   db.collection("profile").add(this.profile)
}
}

I want a placeholder like this我想要一个这样的占位符

在此处输入图片说明

 var app = new Vue({ el: '#app', data: { selected: '' }, watch:{ selected:function(){ console.log('selected is ' +this.selected+" do you logic here"); } } })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <body> <div id="app"> <select v-model="selected"> <option value="" disabled selected>Marital Status</option> <option>Married</option> <option>Single</option> <option>Divorced</option> <option>Widow</option> </select> Selected:{{selected}} </div> </body>

Are you looking for something like this?你在寻找这样的东西吗?

    <select name="maritalStatus" v-model="selected">
        <option value="" disabled selected>Marital Status</option>
        <option>Married</option>
        <option>Single</option>
        <option>Divorced</option>
        <option>Widow</option>
    </select>

Additionally you can add a watcher to call save()此外,您可以添加一个观察者来调用 save()

watch:{
  selected:function(new,old){
   //write your logic here
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置 vue.js 2 中选定的选项? - How can I set selected option selected in vue.js 2? 如果表单中有错误,我该如何添加selected = selected来保存我的下拉菜单? - How can i add selected=selected to save my dropdown if there is an error in my form? 如何通过跟踪选项进行选择,将所选对象以角度保存在模型中? - How can I make a select with a track by option save the selected object in the model in angular? 如何在Jade中选择一个选项? - How can I make an option selected in Jade? 在 HTML 表单中选择选项时,如何使用 JS 删除标签? - how can I use JS to Remove a tag off when a Option is selected in a HTML form? 我怎样才能console.log从有角度的Material表格和表格中选择的选项? 角度4 - How can I console.log the selected option from angular Material form and table? ANGULAR 4 如何使用 D3(或仅使用 javascript)将表单选项设置为“已选择” - How can I use D3 (or just javascript) to set a form option as being "selected" 如何从 HTML 表单中将选定的选项值添加到 jQuery 多选? - How can I add selected option values to a jQuery multiselect from a HTML form? 我怎样才能把选择的选项 <select>从动态生成的表单到输入字段 - How can I put the selected option of a <select> from a dynamically generated form into an input field 使用JavaScript,我如何重置表单中的所有选择,以便选择每个选项的第一个选项? - Using JavaScript, how can I reset all the select's in my form so that the first option for each is selected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM