My Vuetify Switch not change his value?

三世轮回 提交于 2019-12-11 04:47:53

问题


I have a vuetify switch that should receive value from the API True or False.

The API returns True, but the Switch always shows False.

<v-switch label="Habilitado">{{props.item.habilitado}}</v-switch>

The switch is inside an a vuetify data table with others values. The other values receive data, but seems the switch not.

My items in data() return:

   items:[{
    habilitado: "",
}],

In Postman shows True the value

My axios Get Method:

    cargarTanques(){
    axios
  .get("http://localhost:58209/api/Tanque/GetTanques", {
    headers: {
      Authorization: "Bearer " + localStorage.getItem("token")
    }
  })
  .then(response => {
    console.log(response);
    this.items = response.data;
    //this.snackbar = true;
    //this.textSnackbar = "Se han cargado correctamente las estaciones";
  })
  .catch(error => {
    console.log(error.response);
    this.snackbar = true;
    this.textSnackbar =
      "Lo sentimos, no pudimos cargar la información de los tanques";
  });
},

Thank you

EDIT

The class which receives the value has: public bool Habilitado {get; set;}


回答1:


<v-switch v-model="props.item.habilitado" label="Habilitado" />

I assume the "props" comes from a scoped slot




回答2:


It appears that you are setting the field as a string with " " instead of a boolean which could be set to null and then when updated by the API would update to a boolean. Switches use boolean values.

https://vuetifyjs.com/en/components/selection-controls#switches-boolean



来源:https://stackoverflow.com/questions/50011826/my-vuetify-switch-not-change-his-value

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