Vuetify Vuex v-for v-switch 默认为 true [英] Vuetify Vuex v-for v-switch default true

查看:58
本文介绍了Vuetify Vuex v-for v-switch 默认为 true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Vuex 商店中有一个值列表,我为其创建了 v-switch,但我希望 v-switch 的默认值在创建时为 true.我试过 input-value=true" 但它什么也没做.任何想法如何将它们设置为 true 因为我在文档中找不到任何对我有帮助的内容?

I have a list of values in the Vuex store that I create v-switches for but I would like for the default value of the v-switch to be true on creation. I have tried input-value="true" but it does nothing. Any ideas how to set them to true since I can not find anything in the documentation that helps me?

<v-switch
        v-for="(layerg, k) in getAddedGeoMetLayers"
        :key="k"
        :label="layerg"
        :value="layerg"
        dense
        hide-details
        v-model="selectedGeometLayers"
        @change="updateSelectedAddedGeoMetLayers"
        ></v-switch>

export default {
  mounted () {
    this.selectedGeometLayers = this.getSelectedAddedGeometLayers
  },
  data () {
    return {
      selectedGeometLayers: []
    }
  },
  computed: {
    ...mapGetters('map', [
      'getSelectedAddedGeometLayers'
    ])
  },
  methods: {
    updateSelectedAddedGeoMetLayers: function () {
      this.$store.dispatch('map/updateSelectedAddedGeometLayers', this.selectedGeometLayers)
    }
  }

推荐答案

你需要设置 selectedValues Array 等于 getArray - 这样所有的 v-switch 会在开头被选中:

You need to set selectedValues Array to equal the getArray - this way all the v-switch will be selected at the beginning:

mounted() {
    this.selectedValues = [...this.getArray]
}

这篇关于Vuetify Vuex v-for v-switch 默认为 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆