简体   繁体   English

如何根据文本框 vue.js 上的指定数字添加行

[英]How to add rows base on the specified number on textbox vue.js

Hello everyone I'm new at making app using vue.js I'm wondering How to add rows base on the specified number on textbox.大家好,我是使用 vue.js 制作应用程序的新手,我想知道如何根据文本框上的指定数字添加行。

this is my fiddle这是我的小提琴

https://jsfiddle.net/7nxhygLp/2/ https://jsfiddle.net/7nxhygLp/2/

script脚本

    var evaluate  = new Vue({
  el: "#evaluate",
  data: {
    rows: [
    ]
  },
  methods:{
    addRow: function(){
      this.rows.push({});
    },
    removeRow: function(row){
      //console.log(row);
      this.rows.$remove(row);
    }
  }
});

You can use v-model to retrieve the value of the input box, and then just push that many new rows:您可以使用v-model来检索输入框的值,然后只需推送那么多新行:

HTML HTML

<input type="text" v-model="rowCount" name="rows" class="rows-textbox">

JS JS

data: {
    rowCount:0,
    rows: [
    ]
  },
  methods:{
    addRow: function(){
      for(i = 0; i < this.rowCount; i++){
        this.rows.push({});
      }
      this.rowCount = 0;
    },
  }

Fiddle小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM