我试图从枚举模型中获取价值,但我不怎么做:/我花了很多时间在此上,但仍然无法解决这个问题。
我的型号代码:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const taskSchema = new Schema ({
title: {
type: String,
required: true,
},
priority: {
type: String,
enum: ['low', 'medium', 'height'],
default: 'low',
},
progress: {
type: String,
enum: ['0%', '10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'],
default: '0%',
},
});
module.exports = mongoose.model('Task', taskSchema);
我的组件:
<select
:value="task.priority">
<option :value="task.priority" disabled>{{task.priority}}</option>
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="height">Height</option>
</select>
Script:
export default {
props: {
task: {
type: Object,
required: true,
priority: ['low', 'medium', 'height']
},
}
}
我尝试过类似的操作,但是我只需要一个option即可选择值。例如,我在“项目/任务或其他项目”中具有“中”值,然后打开它进行编辑,因此我将有重复的“中”值,因为在创建过程中我选择了“中”。
我尝试使用v-for指令执行任务,但未得到任何结果。
您无法设置:value="task.priority"
,因为task.priority
是一个数组。您应该选择一个值(低,中或高)。这是我如何使用select的方法:
<select name="name" class="form-control" v-model="field">
<option v-for="option in param.options" :value="option.value">{{$t(option.option)}}</option>
</select>
如您所见,我将选择的值存储到field
数据属性中。您也可以查看有关选择https://vuejs.org/v2/guide/forms.html#Select的文档。