简体   繁体   English

Vue JS Make 下拉 select 选择选项时运行查询

[英]Vue JS Make drop-down select run query when option selected

I am very new to Vue and stuck on a problem.我对 Vue 很陌生,遇到了一个问题。 I have several drop-down select menus which return info from an Axios request The select t only works when I hit the submit button though.我有几个下拉 select 菜单,它们从 Axios 请求返回信息 select t 仅在我点击提交按钮时才有效。 I would like it to run when the user makes the drop-down selection.我希望它在用户进行下拉选择时运行。 I can't work out what I am missing.我无法弄清楚我错过了什么。 Can anyone help?任何人都可以帮忙吗?

I have included some of the code below.我在下面包含了一些代码。 Thanks谢谢

The html: html:

 <div class="form-group col-md-6">
                      <label for="subject" class="control-label">Subject</label>
                      <select
                        v-model="subject"
                        class="form-control"
                        :disabled="selectDisabledSubject"
                      >
                        <option disabled value="">Select subject</option>
                        <option
                          v-for="subject in uniqueSubjects"
                          :key="subject"
                          :value="subject"
                        >
                          {{ subject }}
                        </option>
                      </select>
                    </div>

The vue视图

uniqueSubjects() {
      const metaVFees = this.results
        .filter((result) => result.metaData && result.metaData.V)
        .map((item) => item.metaData.V)
        .filter((subject, i, arr) => arr.indexOf(subject) === i);
      // Split multiple subjects in strings and store in an array
      let subjects = [];
      metaVFees.forEach((item) => {
        const splitArr = item.split(", ");
        subjects = subjects.concat(splitArr);
      });
      return subjects
        .sort()
        .filter((subjects, i, arr) => arr.indexOf(subjects) === i);
    },

You can use vue Watchers你可以使用 vue观察者

watch:{
 subject(newVal){
  // call the function you normally call with submit click
 }
}

暂无
暂无

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

相关问题 HTML 选择较短选项时下拉更改大小 - HTML drop-down change size when shorter option selected 即使下拉选择具有相同的名称,也如何获取选择的选项 - How to get the selected option only even though the drop-down select has the same name 选择选择:已选择的其他下拉菜单中的“禁用”选项 - Chosen select: Disable option in other drop-down which already selected 在下拉列表中有效获取所选选项(XHTML选择元素) - Efficiently get selected option in a drop-down list (XHTML Select element) (Django)如何在更改外键下拉列表后使“选定”选项有效? - (Django) How do I make the 'selected' option valid after altering a foreign key drop-down? 如何使用D3.js从下拉列表中设置最后一个选项 - How to set the last option from a drop-down list as selected using D3.js 如何在Angular JS的选择列表中选择默认下拉选项 - How to select default drop-down option in select list in Angular JS React.js 控制 select 选项(下拉) select 改变值 - React.js controlled select option (drop-down) select the changed value 如何使用取决于另一个下拉列表中所选选项的下拉列表显示表格简码 - how to display table shortcode with a drop-down list that depends on the selected option in another drop-down list 根据另一个下拉列表中的所选选项更改下拉列表中的项目 - Change items in a drop-down list depending on the selected option in another drop-down list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM