Vue dynamically generates dom and automatically binds events. vue dynamically binds dom

Source: Internet
Author: User

Vue dynamically generates dom and automatically binds events. vue dynamically binds dom

When using jquery, you will find that the dom dynamically generated after page rendering cannot be obtained from the code before it is generated and must be retrieved again. however, based on the data binding feature, vue enables it to directly bind data when it is generated.

Html:

<Div id = "app"> <table v-for = "table in tables"> <tr v-for = "row in table. row "> <td style =" width: 80px; float: left "v-for =" item in row "> <input type =" text "v-model =" item. val "style =" width: 40px "> <div style =" width: 40px; float: left ">{{ item. val }}</div> </td> </tr> </table> <button v-on: click = "add"> add a 2x2 Table </button> </div>

Js:

<script src="https://unpkg.com/vue/dist/vue.js"></script><script type="text/javascript">    var vm = new Vue({   el : "#app",   data:{    tables : []   },   methods:{      add:function(){      row = [];      rmax = 2;      cmax = 2;       for( i = 0; i < rmax; i++){        column = [];        for( f = 0; f < cmax; f++){          column = column.concat({              val:"",          });        }        row.push(column);      }       this.tables.push({        row:row,      });    }  }   });</script>

You will find that the input value in the input box can be changed directly in the div below, and the data in the date can be directly read to obtain the data in the corresponding table, it can be used directly, and ajax sending does not need to be searched and read again using jquery.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.