【发布时间】:2020-02-28 06:06:29
【问题描述】:
我有一个带有 vuex 反应式自动保存应用程序的 vue,我使用 bootstrap-select 作为尝试自动保存的字段之一。
我在 vue 组件的 mount() 生命周期钩子中声明了 bootstrap-select 监听器,如下所示:
mounted() { //vue mounted hook
const selectpicker = $(this.$el).find('.selectpicker')
selectpicker.selectpicker('val', this.selected); //this shows previously saved 'selected' items
function callback() {
this.callVueComponentMethod() //throws 'this.* is not a function'
}
selectpicker.selectpicker().on('changed.bs.select', callback());
}
我在挂载的钩子中声明它,因为这是我让它工作得最好的方式......但是现在我想尝试$emit 父 vue 组件的函数,当引导程序上的选择发生变化时,选择所以我需要以某种方式访问 bootstrap-select 侦听器中的 this 对象,以调用链上的 $emit 以最终保存选择更改。
我可能遗漏了一些东西,但我觉得问题在于将 this 对象放入 selectpicker 侦听器范围?
感谢所有建议!谢谢:)
【问题讨论】:
-
你试过直接在
<select></select>标签上监听@change事件吗?
标签: javascript vue.js bootstrap-4 scope bootstrap-select