Javascript vue.js select中的设置值给出了“未定义”值

Javascript vue.js select中的设置值给出了“未定义”值,javascript,vue.js,Javascript,Vue.js,当vue组件通过websocket接收更新时,它会为设置新值 相关代码 window.VueBus.$on("updated", (channel, key, value) => { let selfChannel = "model." + self.model + "." + self.pk; if(channel === selfChannel) { if(self.key =

当vue组件通过websocket接收更新时,它会为
设置新值

相关代码

            window.VueBus.$on("updated", (channel, key, value) => {
             let selfChannel = "model." + self.model + "." + self.pk;
             if(channel === selfChannel) {
                 if(self.key === key) {
                     console.log("Set " + key + " to " + value);
                     self.input.off("change");
                     console.log("off handler");
                     self.value = value; // when I set value here error happens
                     self.$nextTick(() => {
                         self.input.on("change", this.onInputChange);
                         console.log("on handler");
                         self.initInput(true);
                     });
                 }
             }
         });
我增加了手表功能

        watch: {
         value: function(old, newv) {
             console.log('old-new');
             console.log(old)
             console.log(newv)
         }
     },
当我打开两个浏览器窗口并在其中一个窗口中进行更改时,这就是它给我的

old-new
19
      # it is just an empty string
old-new
undefined
19
但我看到正确的值被传递到组件中

Set recommender_id to 19
off handler # it is required because onInputChange makes requests to server
控制台上的错误

TypeError: Cannot read property 'length' of undefined
这是因为模板中的这一行

<div v-bind:class="{'floating-label-form-group-with-value': value.length > 0}">

在另一个窗口(我在其中进行更改)中,一切正常。

解决方案很简单:

v-model on如果缺少匹配项,则将值设置为未定义