vue generates table and sorts it
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); } } }); }
function rownum(){ //首先拿到table中tr的数量 得到一共多少条数据 var len = $("#tableId table tbody tr").length; //使用循环给每条数据加上序号 for(var i = 1;i<len+1;i++){ $('#tableId table tr:eq('+i+') span:first').text(i); } }
var model={ object[] } spnetPagerInfoIM(electricalPageDataShow, electricalPageModule, electricalResource, function(result) { model.object = result; Vue.nextTick(function(){ rownum(); }); });
vm.$nextTick( [callback] )
Vue.nextTick( [callback, context] )
<ul id="demo"> <li v-for="item in list">{{item}}</p> </ul> new Vue({ el:'#demo', data:{ list=[0,1,2,3,4,5,6,7,8,9,10] }, methods:{ push:function(){ this.list.push(11); this.nextTick(function(){ alert('数据已经更新') }); this.$nextTick(function(){ alert('v-for渲染已经完成') }) } }})
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); });
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',DOM
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)
Require to call js to use Detailed 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!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This article will introduce how to sort pictures according to shooting date in Windows 11/10, and also discuss what to do if Windows does not sort pictures by date. In Windows systems, organizing photos properly is crucial to making it easy to find image files. Users can manage folders containing photos based on different sorting methods such as date, size, and name. In addition, you can set ascending or descending order as needed to organize files more flexibly. How to Sort Photos by Date Taken in Windows 11/10 To sort photos by date taken in Windows, follow these steps: Open Pictures, Desktop, or any folder where you place photos In the Ribbon menu, click

Outlook offers many settings and features to help you manage your work more efficiently. One of them is the sorting option that allows you to categorize your emails according to your needs. In this tutorial, we will learn how to use Outlook's sorting feature to organize emails based on criteria such as sender, subject, date, category, or size. This will make it easier for you to process and find important information, making you more productive. Microsoft Outlook is a powerful application that makes it easy to centrally manage your email and calendar schedules. You can easily send, receive, and organize email, while built-in calendar functionality makes it easy to keep track of your upcoming events and appointments. How to be in Outloo

PHP development: How to implement table data sorting and paging functions In web development, processing large amounts of data is a common task. For tables that need to display a large amount of data, it is usually necessary to implement data sorting and paging functions to provide a good user experience and optimize system performance. This article will introduce how to use PHP to implement the sorting and paging functions of table data, and give specific code examples. The sorting function implements the sorting function in the table, allowing users to sort in ascending or descending order according to different fields. The following is an implementation form

Generating random data is very important in the field of data science. From building neural network predictions, stock market data, etc., date is usually used as one of the parameters. We may need to generate random numbers between two dates for statistical analysis. This article will show how to generate k random dates between two given dates using the random and datetime modules. Datetime is Python’s built-in library for handling time. On the other hand, the random module helps in generating random numbers. So we can combine random and datetime modules to generate a random date between two dates. Syntax random.randint (start, end, k) random here refers to the Python random library. The randint method uses three important

In this problem, a string is given as input and we have to sort the words appearing in the string in lexicographic order. To do this, we assign an index starting from 1 to each word in the string (separated by spaces) and get the output in the form of sorted indices. String={"Hello","World"}"Hello"=1 "World"=2 Since the words in the input string are in lexicographic order, the output will print "12". Let's look at some input/result scenarios - Assuming all words in the input string are the same, let's look at the results - Input:{"hello","hello","hello"}Result:3 Result obtained

How does Arrays.sort() method in Java sort arrays by custom comparator? In Java, the Arrays.sort() method is a very useful method for sorting arrays. By default, this method sorts in ascending order. But sometimes, we need to sort the array according to our own defined rules. At this time, you need to use a custom comparator (Comparator). A custom comparator is a class that implements the Comparator interface.

How to use PHP to generate refreshable image verification codes. With the development of the Internet, in order to prevent malicious attacks and automatic machine operations, many websites use verification codes for user verification. One common type of verification code is the image verification code, which generates a picture containing random characters and requires the user to enter the correct characters before proceeding. This article will introduce how to use PHP to generate refreshable image verification codes and provide specific code examples. Step 1: Create a verification code image First, we need to create a verification code image

How to generate QR code with time limit using PHP? With the popularity of mobile payments and electronic tickets, QR codes have become a common technology. In many scenarios, we may need to generate a QR code with a time limit, which will become invalid even after a certain period of time. This article will introduce how to use PHP to generate a time-limited QR code and provide code examples for reference. Installing the PHPQRCode library To use PHP to generate QR codes, we need to install the PHPQRCode library first. This library
