This time I will bring you Vue to generate a table and sort it. What are the precautions for Vue to generate a table and sort it? The following is a practical case, let's take a look.
Now there is a table generated using the mybatis paging plug-in. The data in the table is obtained through vue. The front-end display usesThe background vue gets the data and uses the paging plug-in to query and then uses the callback to return the result to a model of vue
/** * 分页控件加载 * @param data */ function aspnetPagerInfoIM(pageDataShow,pageModule,resource, modelCallBack) { var pageDataShow = $("#"+pageDataShow); var pageModule = $("#"+pageModule); pageDataShow.empty(); pageModule.empty(); resource.get({ page: '0' }).then(function(response){ initLaypage(pageDataShow,pageModule,response.data, resource, modelCallBack); modelCallBack(response.data.content); }) } /** * 初始化分页组件 * @param page 查询出来的数据包括分页信息 * @param resource vue的resource对象 * @param modelCallBack 每次页面跳转回调方法 modelCallBack(response.data.content) */ function initLaypage(pageDataShow,pageModule,page, resource, modelCallBack) { var singleInvoke = false laypage({ cont : pageModule, pages : page.totalPages, //总页数 skin : '#fff', //加载内置皮肤 skip: true, //是否开启跳页 groups : 5, //连续显示分页数 hash : true, //开启hash jump : function(obj) { if(!singleInvoke) { singleInvoke = true; }else { resource.get({ page: obj.curr -1 }).then(function(response){ modelCallBack(response.data.content); }) } pageDataShow.empty(); if(page.totalElements>0){ $("<p>共"+page.totalElements+"条记录," +"每页"+page.size+"条," +"当前第 "+obj.curr +"/"+page.totalPages+"页" +"</p>").appendTo(pageDataShow); } } }); }The requirement is: add a serial number to the generated table Just started using js functions
function rownum(){ //首先拿到table中tr的数量 得到一共多少条数据 var len = $("#tableId table tbody tr").length; //使用循环给每条数据加上序号 for(var i = 1;i<len> Put the above method on the <p style="text-align: left;"> event<a href="http://www.php.cn/js/js-jspopular-guide-event.html" target="_blank"> of clicking to generate the table, you can display the serial number, then click the next page or page number of the paging, and when you jump to the next page, the serial number disappears, </a> </p> It is natural to think that there should be an operation of adding a serial number after clicking the next page, so I found a way to display the data on the next page, and added the above js method, but the result did not take effect, <p style="text-align: left;"></p> Personally, I think that after the data was found, the rownum method was added before the dom was refreshed, and then after the dom was updated, the serial number disappeared<p style="text-align: left;"></p> The problem was finally solved by searching for information as follows, adding the Vue.nextTick(function(){}) method<p style="text-align: left;"></p> <pre class="brush:php;toolbar:false">var model={ object[] } spnetPagerInfoIM(electricalPageDataShow, electricalPageModule, electricalResource, function(result) { model.object = result; Vue.nextTick(function(){ rownum(); }); });wherever paging queries appear. 1.
vm.$nextTick( [callback] )
Vue.nextTick( [callback, context] )
- {{item}}
this.$http.post(apiUrl) .then((response) => { if (response.data.success) { this.topFocus.data = response.data.data; this.$nextTick(function(){ //渲染完毕 }); } }).catch(function(response) { console.log(response); });When do you need to use Vue.nextTick() The
DOM operations you perform in the created() hook function of Vuelifecycle must be placed in the callback function of Vue.nextTick(). What is the reason? The reason is that when the created() hook function is executed, the DOM In fact, no rendering is performed, and DOM operations at this time are in vain, so the js code for DOM operations must be put into the callback function of Vue.nextTick(). Corresponding to it is the mounted hook function, because all DOM mounting and rendering have been completed when the hook function is executed. At this time, there will be no problem in performing any DOM operations in the hook function. .
When there is an operation to be performed after the data changes, and this operation requires the use of a DOM structure that changes as the data changes, this operation should be put into the callback function of Vue.nextTick(). Vue performs DOM updates asynchronously. Once data changes are observed, Vue will open a queue and then update it in the same event loop. watcher that observes data changes Push into this queue. If this watcher is triggered multiple times, it will only be pushed to the queue once. This buffering behavior can effectively eliminate unnecessary calculations and DOm operations caused by duplicate data. In the next event loop, Vue will clear the queue and perform the necessary DOM updates. When you setvm.someData = 'new value',DOMIt will not be updated immediately, but the necessary DOM updates will be performed when the asynchronous queue is cleared, that is, when the update is performed at the beginning of the next event loop. If at this time you want to use the updated DOM If you do something in a certain state, problems will arise. . In order to wait for Vue to finish updating the DOM after the data changes, you can use immediately after the data changes. Vue.nextTick(callback) . This callback function will be called after the DOM update is completed.
Summarize:
* `Vue.nextTick(callback)`, when the data changes, the callback is executed after updating.* `Vue.$nextTick(callback)`, when the dom changes, the callback is executed after updating.
Popup popup box binding to add data event (detailed step-by-step explanation)
The above is the detailed content of vue generates table and sorts it. For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
