Vue.js 创建显示来自所选数据集的数据的选择器

Vue.js create selector that shows Data from selected Dataset

大家好我尝试创建一个 select 输入字段,我在其中使用我创建的数据集中的标签填充选项,如下所示:

visitsList: [
                    {
                    label: '2017',
                    values: [
                        { id: 1, title: "January", value: 20000 },
                        { id: 2, title: "February", value: 30000 },
                        {id: 3,title: "March", value: 40000},
                        { id: 4, title: "April", value: 40000},
                        {id: 5,title: "May",value: 50000},
                        { id: 6,title: "June",value: 60000},
                        {id: 7, title: "July",value: 20000},
                        { id: 8,title: "August", value: 70000},
                        { id: 9,title: "September",value: 70000},
                        {id: 10, title: "October",value: 80000},
                        {id: 11,title: "November",value: 90000},
                        {id: 12,title: "December",value: 100000}
                    ]},
                    {
                    label: '2018',
                    values: [
                        { id: 1, title: "January", value: 20000 },
                        { id: 2, title: "February", value: 30000 },
                        {id: 3,title: "March", value: 40000},
                        { id: 4, title: "April", value: 40000},
                        {id: 5,title: "May",value: 50000},
                        { id: 6,title: "June",value: 60000},
                        {id: 7, title: "July",value: 20000},
                        { id: 8,title: "August", value: 70000},
                        { id: 9,title: "September",value: 70000},
                        {id: 10, title: "October",value: 80000},
                        {id: 11,title: "November",value: 90000},
                        {id: 12,title: "December",value: 100000}
                    ]},
                    {
                    label: '2019',
                    values: [
                        { id: 1, title: "January", value: 20000 },
                        { id: 2, title: "February", value: 30000 },
                        {id: 3,title: "March", value: 40000},
                        { id: 4, title: "April", value: 40000},
                        {id: 5,title: "May",value: 50000},
                        { id: 6,title: "June",value: 60000},
                        {id: 7, title: "July",value: 20000},
                        { id: 8,title: "August", value: 70000},
                        { id: 9,title: "September",value: 70000},
                        {id: 10, title: "October",value: 80000},
                        {id: 11,title: "November",value: 90000},
                        {id: 12,title: "December",value: 100000}
                    ]
                    }   
              ],
              selectedYear: [],

目标是如果我 select 一个带有年份的选项,它应该显示值。 模板看起来像这样

 <select v-model="widget.selectedYear">
                    <option v-for="year in widget.visitsList" v-bind:key="year.values">
                        {{year.label}}
                    </option>
                </select>
                <!--v-select :option="widget.visitsList.label" ></v-select-->
              <table class="table table-bordered table-striped mb-0">
                <thead>
                  <tr>
                    <th scope="col">Month</th>
                    <th scope="col">Views</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="year in widget.visitsList" v-bind:key="year.label" ><!--v-if="year.label == selectedYear"-->
                        <th scope="row">{{visit.title}}</th>
                        <td>{{visit.value}}</td>
                    </div>
                  </tr>
                </tbody>
              </table>

我尝试了很多东西,但不知何故我没有找到正确的解决方案。也许没有解决办法。 谢谢您的帮助 问候马克西姆

我认为你应该为此使用计算属性,将你的第一个 selector 绑定到数据 属性 然后你可以有一个计算 属性 观察数据 属性 和 return 第二个 select 的值基于数据 属性 的变化。