A simple example of implementing search and news list functions in Vue
This article introduces you to a simple example of Vue's implementation of search and news list functions through example code. It is very good and has reference value. Friends who are interested can take a look.
The renderings are as follows:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>无标题页</title> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <meta name="format-detection" content="email=no"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=0"> <script src="/style/js/vue.min.js" type="text/javascript"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/vue-resource/0.1.17/vue-resource.js"></script> <style> .box { width: 900px; height: auto; overflow: hidden; margin: 30px auto; } .left { height: 150px; width: 185px; padding: 5px; display: inline-block; border: 1px solid black; } .left input { padding: 2px; margin-top: 10px; } .right { width: 600px; height: auto; display: inline-block; margin-left: 30px; vertical-align: top; } .right table { border-collapse: collapse; width: 580px; } .right table th { background-color: green; padding: 5px; text-align: center; border: 1px solid black; color: #FFFFFF; } .right table tr { text-align: center; } .right table td { border: 1px solid black; } </style> </head> <body> <p id="app"> <p class="box"> <p class="left"> <input type="text" placeholder="输入编号" v-model="id" /> <input type="text" placeholder="输入名称" v-model="name" /><br /> <input type="button" value="添加数据" @click="add" /> <input type="text" placeholder="搜索数据" v-model="search" /> </p> <p class="right"> <table> <tr> <th>编号</th> <th>品牌名称</th> <th>创建时间</th> <th>操作</th> </tr> <tr v-for="item in searchData"> <td>{{item.id}}</td> <td>{{item.name}}</td> <td>{{item.time | datefmt('yyyy-mm-dd HH:mm:ss')}}</td> <td> <a href="javascript:void(0)" rel="external nofollow" @click="del(item.id)">删除</a> </td> </tr> </table> </p> </p> </p> <script> //定义全局过滤器 Vue.filter("datefmt", function (input, formatstring) { var result = ""; var year = input.getFullYear(); var month = input.getMonth() + 1; var day = input.getDate(); var hour = input.getHours(); hour = hour < 10 ? "0" + hour : hour; var minute = input.getMinutes(); minute = minute < 10 ? "0" + minute : minute; if (formatstring == 'yyyy-mm-dd') { result = year + "-" + month + "-" + day; } else { result = year + "-" + month + "-" + day + " " + hour + ":" + minute; } return result; }) var TEMPLATE={ options:function(){ /** <a class="weui_cell" href="javascript:void(0);" rel="external nofollow" > <p class=weui_cell_hd > <i class="fa fa-credit-card fa-2x icon-color" style=width:35px;margin-right:15px;display:block ></i> </p> <p class="weui_cell_bd weui_cell_primary" > <p > {{HospPatientName}} <span style=margin-left:15px class=blue_tag >{{HospCardType}}</p> <p >{{HospCardNo}}</p></p> <p class=weui_cell_ft > {{HospIsDefault}} </p> </a> */ } }; var vm = new Vue({ el: '#app', data: { id: '', name: '', search: '', list: [{ "id": 1, "name": "宝马", "time": new Date() }, { "id": 2, "name": "奔驰", "time": new Date() } ] }, methods: { del: function (id) { if (!confirm("是否删除数据?")) { return; } //调用list.findIndex()方法,根据传入的id获取到这个要删除数据的索引值 var index = this.list.findIndex(function (item) { return item.id == id; }); //调用list.splice(删除的索引,删除的元素个数) this.list.splice(index, 1); }, add: function () { //包装成list要求的对象 var tem = { id: this.id, name: this.name, time: new Date() }; //将tem追加到list数组中 this.list.push(tem); //清空页面上的文本框中的数据 this.id = ""; this.name = ""; } }, computed: { searchData: function () { var search = this.search; if (search) { return this.list.filter(function (name) { return Object.keys(name).some(function (key) { return String(name[key]).toLowerCase().indexOf(search) > -1 }) }) } return this.list; } } }) </script> </body> </html>
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
In-depth understanding of the Node module module
Summary of the method of converting JS from non-array object to array
js canvas implements the sliding puzzle verification code function
The above is the detailed content of A simple example of implementing search and news list functions in Vue. For more information, please follow other related articles on the PHP Chinese website!

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.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

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.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
