VUEX NUXT MAPSTATE:DOM对VUEX状态不反应

发布于 2025-02-06 04:40:41 字数 1323 浏览 0 评论 0原文

我想做2个Vuetify V-Switch。 第一个在True/False上切换布尔值。 第二,如果第一个是错误的,则将被禁用,如果其为false,则不是。 如果当第二个交换机在第二个为true时作为false传递,则应将第二个开关设置为false,因此将其设置为禁用。

这是我到目前为止所做的:

 computed: {
    ...mapState({
      propertyType: state => state.propertyTypes.current
    })
  }

这是您所看到的2个开关的代码

  <v-switch
    id="is-filter"
    v-model="propertyType.is_filter"
    flat
    class="mt-0"
    @change="propertyType.default_filter = false
  >
    // template stuff
  </v-switch>
  <v-switch
    id="default-filter"
    v-model="propertyType.default_filter"
    :disabled="!propertyType.default_filter"
    flat
    class="mt-0"
  >
    // template stuff
  </v-switch>

,V模型设置在“导入”状态对象上。请注意,state.propertytypes.current是一个对象,并且具有倍数键和值。

我在这里遇到的问题是,每当我切断第二个开关时,第二个开关都会被禁用,但是它的值不会在dom中变化。 VUEX状态对象已更新,但没有更新DOM。

请参阅图像,代表“ Vuex绑定”导入但MapState

dom:

”在此处输入图像描述“

我该如何修复此问题并使DOM重新为此Vuex bindings对象?

感谢您的任何帮助!

I'd like to make 2 vuetify v-switch.
The first one toggle a boolean on true/false.
The second, is disabled if the first one is false, and isnt if its true.
If the first switch is passed as false when the second is true, the second should be set to false and therefore, disabled.

Here is what I've done so far :

 computed: {
    ...mapState({
      propertyType: state => state.propertyTypes.current
    })
  }

Here are the code for the 2 switches

  <v-switch
    id="is-filter"
    v-model="propertyType.is_filter"
    flat
    class="mt-0"
    @change="propertyType.default_filter = false
  >
    // template stuff
  </v-switch>
  <v-switch
    id="default-filter"
    v-model="propertyType.default_filter"
    :disabled="!propertyType.default_filter"
    flat
    class="mt-0"
  >
    // template stuff
  </v-switch>

As you can see, the v-model is set on the "imported" state object. Note that state.propertyTypes.current is an object, and has multiples keys and values.

The issue i'm having here is whenever i toggle off the first switch when the second is true, the second is set disabled, but it's value doesn't change in DOM. The vuex state object is updated, but not the DOM.

See image, representing the "vuex bindings" imported but mapState
enter image description here

DOM :

enter image description here

How can I fix this and have DOM to be reactiv to this vuex bindings objects ?

Thanks by advance for any help !

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三岁铭 2025-02-13 04:40:41

您无法从类似的计算中调用MapState:
这是我的代码的副本,该副本显示了名称和状态名称:

computed: {
        ...mapState("your_vuex_namespace_name", ["propertyType"]),
    }

我希望它能帮助您。

You cannot call mapState from computed like that:
Here is a copy of my code which shows the namespace and state name:

computed: {
        ...mapState("your_vuex_namespace_name", ["propertyType"]),
    }

I hope it helps you out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文