javascript - vuejs - 引导选择选项不起作用
问题描述
我有这个选择:
<select v-model="filterState" @change="search()" class="selectpicker livesearch form-control" ref="stateSelect" id="stateSelect">
<option value="">Alle Status</option>
<option v-for="assignmentState in assignmentStates" v-bind:value="assignmentState.state">
{{ assignmentState.state }}
</option>
</select>
只有当我像这样刷新它时它才会起作用:
export default {
name: "AssignmentList",
data() { ....
},
updated() {
$(this.$refs.stateSelect).selectpicker('refresh');
}
但是使用这种方法,“livesearch”之类的选项不起作用。
// Select2 Livesearch
$('.livesearch').selectpicker({
liveSearch: true,
noneSelectedText: 'Nichts ausgewählt',
});
我只能使用“data-live-search”属性启用实时搜索,如下所示:
<select v-model="filterState" @change="search()" data-live-search="true" class="form-control" ref="stateSelect" id="stateSelect">
但我想在我的 JS 文件中设置选项而不使用数据属性。
我该怎么做?
解决方案
v-for
您需要绑定密钥的第一件事,请参阅文档以获得更好的解释。
第二个建议,如果可以的话,不要将 jquery 与 vue 混合使用,你不需要这样做,例如:
$(this.$refs.stateSelect).selectpicker('refresh');
可:
this.$refs.stateSelect.selectpicker('refresh'); // this can be wrong because selectpicker need a jquery object, but se the logic XD
我不太明白你的目的是什么,但我认为你可以使用手表挂钩:
watch: {
filterstate(){//v-model of select
$('.livesearch').selectpicker({
liveSearch: true,
noneSelectedText: 'Nichts ausgewählt',
});
}
}
使用 vue 作为 ui,您可以使用bootstrap-vue或vuetify
推荐阅读
- python - 在 Pandas 中,一个单元格的字典键、值对到名称为键、行为值的列
- sdl - 每个纹理都应该在 SDL 中拥有自己的专用渲染器吗?
- python - 如何计算移动设备的纵横比?
- google-bigquery - BigQuery - 跨多个表读取时选择分区键
- php - 在php中调用接口方法时出错
- ruby-on-rails - ActiveRecord::NoDatabaseError: FATAL: role "postgres" does not exist when I try to migrate bd in rails
- r - how to group a column and that the other column is grouped to generate a contingency table in R
- python - 如何在 wx python 中使用文本大小更改文本框的大小?
- deep-learning - 为什么过滤器和要素层具有相同数量的通道?
- android - 从卡片视图访问活动中的按钮