vue.js观察器值不更新选择V-Model中的值

发布于 2025-02-02 20:10:20 字数 1275 浏览 3 评论 0原文

我有一个带有两个选择盒的表格。SB1和SB2。带有V模型的SB2:结果。

如果我更改第一个值(SB1)的值,则必须使用该值进行一些异步操作,并获得必须放置在另一个选择框(SB2)中的新值。为此,我使用了一个手表来执行异步量,并且在获得异步值之后,我将其制作。Result= newValue。 在控制台中。log还可以,但在选择框(SB2)中不显示什么都没有显示 但是,然后,当我在第一个框(SB1)中取消一个值时,我先前获得的值

通常在(SB2)中显示出来时,这里发生了什么?我该如何解决这个问题? 预先感谢

编辑:

           <label for="timezone" >Timezone</label>
            <select
              id="timezone"
              v-model="localValue.timezone"
            >
                <option v-for="(timeZone, index) in arrayTZ()" :key="index" :value="timeZone" :selected="localValue.timezone === timeZone">
                    {{ timeZone }}
                </option>
            </select>

和观察者

methods:{
   async getFunction1(id){
     await dispatchingActions
     return objectFromgetFunction1.current
   }
},
watch: {
      async "localValue.ManagerId"(id){
          console.log(id)
          if(id !== null){            
            await this.getFunction1(id)
              this.localValue.timezone = objectFromgetFunction1.current.timezone;
          }
          if(id === null){
              this.localValue.timezone = null
          }
          console.log(this.localValue.timezone)
      },

I have a form with a two select boxes.sb1 and sb2. sb2 with a v-model: result.

If I change the value of the first one (sb1) I have to do a some async operation with the value and to obtain a new value that must be placed in the other select box(sb2). For this I've used a watch executing an async fuction, and after I obtain the async value I make this.result = newValue.
In the console.log is ok, but not in the select box (sb2) that shows nothing
but then, when I unselect a value in the first box (sb1) the value I previously obtained shows up in (sb2)

in general, what is going on here? How can I workaround this?
Thanks in advance

EDIT:

           <label for="timezone" >Timezone</label>
            <select
              id="timezone"
              v-model="localValue.timezone"
            >
                <option v-for="(timeZone, index) in arrayTZ()" :key="index" :value="timeZone" :selected="localValue.timezone === timeZone">
                    {{ timeZone }}
                </option>
            </select>

and the watcher

methods:{
   async getFunction1(id){
     await dispatchingActions
     return objectFromgetFunction1.current
   }
},
watch: {
      async "localValue.ManagerId"(id){
          console.log(id)
          if(id !== null){            
            await this.getFunction1(id)
              this.localValue.timezone = objectFromgetFunction1.current.timezone;
          }
          if(id === null){
              this.localValue.timezone = null
          }
          console.log(this.localValue.timezone)
      },

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文