【问题标题】:Hide input on submit (VUE)提交时隐藏输入 (VUE)
【发布时间】:2018-03-13 23:18:00
【问题描述】:

我正在开发一个 Vue 应用程序 - 非常简单地说是一个待办事项列表,如下例所示。但是我想在提交时隐藏我的输入字段(并且特此只显示它已经显示的输出),所以我可以进行一个很好的转换,因为每个输入字段应该只添加一个项目。

希望有人能帮我找到一个好的解决方案!

https://jsfiddle.net/541rd96r/

new Vue({
  el: "#madplan",
  data: {
    newTask_mandag: "",
    taskList_mandag: [],
  },

  methods: {
    addTask_mandag: function() {
      var task = this.newTask_mandag.trim();
      if (task) {
        this.taskList_mandag.push({
          text: task
        });
        this.newTask_mandag = "";
      }
    },

    removeSubTask_mandag: function(task) {
      var index = this.taskList_mandag.indexOf(task);
      this.taskList_mandag.splice(index, 1);
    },
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>

<div id="madplan">
  <section>
    <section class="prefetch" class="panel">
      <input class="input typeahead" type="text" placeholder="Tilføj ret til madplanen" v-model="newTask_mandag " v-on:keyup.enter="addTask_mandag">
    </section>

    <details v-for="task in taskList_mandag" v-bind:key="task.text" class="sub-list-item">
      <summary>{{ task.text }} <button v-on:click="removeSubTask_mandag(task)">X</button></summary>

    </details>
  </section>
</div>

【问题讨论】:

  • 对不起,剪断编队不好,是复制粘贴!
  • 你应该格式化你的代码可读

标签: javascript jquery input vue.js


【解决方案1】:

input 标记上添加指令v-if='showInput' 以有条件地显示元素。然后添加计算属性来确定条件,像这样

   computed: {
        showInput: function() {
        return !this.taskList_mandag.length
      }
    },

【讨论】:

  • 非常感谢,这正是我想要的!它在 jsfiddle 中有效,但在我的本地脚本中还没有。不过我会解决的。
  • 不客气。希望你的本地脚本也能正常工作
  • 我做到了,我的 twitter-typeahead 在输入时出现了一些问题。我还有一个问题要问你,我明天会把它作为评论发布 - 除非你对我应该如何做有其他偏好:)
  • 如果该问题与此问题相关,则可以发表评论
  • 嘿,我又发布了一个新问题。 stackoverflow.com/questions/46542883/…
猜你喜欢
  • 2021-04-18
  • 2019-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-09
  • 2013-06-12
  • 2019-05-11
  • 1970-01-01
相关资源
最近更新 更多