简体   繁体   English

Vue.js + Bootstrap-Select:如何避免渲染循环?

[英]Vue.js + Bootstrap-Select: how to avoid render loop?

I'm trying to get Vue.js to play nice with Bootstrap-select , but am completely stumped on how to avoid the render loop between the value being set with .selectpicker('val') , and being constantly updated by Vue. 我正在尝试让Vue.js与Bootstrap-select配合使用 ,但是完全避免了如何避免使用.selectpicker('val')设置的值与Vue不断更新之间的渲染循环。

Example here: 这里的例子:

https://codepen.io/schmoove/pen/EeeVab https://codepen.io/schmoove/pen/EeeVab

vm.$emit('input', this.value) (line 10) vm.$emit('input', this.value) (第10行)

Works, but not with multiple selections. 有效,但不能同时进行多项选择。 However, if you switch to: 但是,如果切换到:

vm.$emit('input', $(this.$el).selectpicker('val')); (replace line 10 with line 9) (将第10行替换为第9行)

It sends the script into an infinite loop. 它将脚本发送到无限循环中。

I'm relatively new to Vue.js and just can't understand how this should work, or if Bootstrap-select is making things particularly difficult. 我是Vue.js的新手,只是不了解它应该如何工作,或者Bootstrap-select是否使事情特别困难。 Any help would be much appreciated! 任何帮助将非常感激!

Change 更改

vm.$emit('input', this.value)

to

vm.$emit('input', vm.value)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM