Vue/vuetify v-switch: what is input-value?

Deadly 提交于 2019-12-08 18:37:59

问题


Can someone explain to me exactly what the input-value attribute does on the v-switch component?

I think it has something to due with using the component with vuex, when you cannot use v-model directly.

It seems to be working for me, but I don't understand it exactly.

You can see the attribute here: https://vuetifyjs.com/en/components/selection-controls#api

Where it is described as: "The v-model bound value".

(I originally found the attribute in an example somehere.)


回答1:


input-value behaves like a default value attribute that you would expect in other components.
Normally v-model is syntax sugar for :value="value" :input="$emit('input', $event.target.value)", but we can change it.

from selectable.js:

model: {
  prop: 'inputValue',
  event: 'change'
},

So the above lines (see vue docs) make your v-model bind to input-value instead of value likely because some components i.e. checkbox (which v-switch uses) have value attribute reserved for something else.

So value attribute is then used to set the value which will be represented when the component is checked.
And in v-switch case v-model is syntax sugar for something like :input-value="value" @change="value = $event"

Codepen



来源:https://stackoverflow.com/questions/51485069/vue-vuetify-v-switch-what-is-input-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!