首页 > 解决方案 > 如何根据VueJS中的条件从元素中删除值

问题描述

我正在尝试通过更改values. 我知道如何隐藏,但我想删除如果已经写了一些东西。hideelementsselectvalues

这是我的代码:

<select v-model="switchopera">
  <option :value="undefined" selected disabled
    >Is the reservation under the same name ?</option>
  <option :value="false"
    >Yes</option>
  <option :value="true"
    >No</option>
</select>

<select
  :required="switchopera ? false : true"
  :value="switchopera ? false : true">
  <option selected disabled>Title (on the reservation)</option>
  <option>Mr</option>
    <option>Mrs/option>
</select>

这是我的 Vuejs 代码:

  data() {
    return {
      switchopera: undefined
    };
  }
};

标签: vue.jshideelement

解决方案


您可以使用 watch 属性来检查和执行操作:

watch: {
switchopera: function(value){
  // do action
}
}

推荐阅读