This article mainly introduces Vue to implement library management, shares the knowledge points used in the library management demo, and summarizes the problems encountered. It has certain reference value. Interested friends can refer to it. I hope it can help everyone. .
The company's projects in the future require the use of vue.js knowledge. I have not learned it in Angular. I only know a little bit about node.js and react, so it is difficult to learn it. If you want to learn vue.js knowledge, the recommended website: http://vuejs.org/
The details are as follows:
1. Knowledge points for library management demo
1. bootstrap: http://getbootstrap.com/
2. vuejs: http://getbootstrap.com/
The specific code is as follows:
html part
<p id="app" class="container"> <table class="table table-bordered"> <p v-for = "book in books"> <tr> <th>书名</th> <th>书的价格</th> <th>书的数量</th> <th>小计</th> <th>操作</th> </tr> <tr v-for = "(index,book ) in books"> <td>{{book.name}}</td> <td>{{book.price}}</td> <td><button @click="book.count&&book.count--">-</button><input type="text" v-model="book.count" /><button @click="book.count++">+</button></td> <td>{{book.price*book.count}}</td> <td><button class="btn btn-danger" @click="deleteBook(book)">删除</button></td> </tr> <tr> <td colspan="5"> 总价{{total}} </td> </tr> </p> </table> <p class="form-group"> <label for="bookname" id="bookname">书名</label> <input type="text" v-model="list.name" class="form-control"/> </p> <p class="form-group"> <label for="bookprice" id="bookprice">价格</label> <input type="text" v-model="list.price" class="form-control"/> </p> <p class="form-group"> <label for="bookcount" id="bookcount">数量</label> <input type="text" v-model="list.count" class="form-control"/> </p> <p class="form-group"> <button class="btn btn-primary" @click="add">添加</button> </p> </p>
script part
<script src="js/vue.js"></script> <script> var vm = new Vue({ el:"#app", data:{ books:[ {name:'VUE js',price:40,count:1}, {name:'NODE js',price:20,count:1}, {name:'REACT js',price:30,count:1}, {name:'ANGULAR js',price:100,count:1}, {name:'JQUERY js',price:50,count:1}, ], list:{ name:'', price:'', count:'' } }, methods:{ deleteBook(book){ // vue 给我们提供了一个 $remove的方法,在数组中删除 this.books.$remove(book); /*this.books = this.books.filter((item)=>{ return item != book })*/ }, add(){ this.books.push(this.list); this.list = { name:'', price:'', count:'' } } }, computed:{ total(){ var sum = 0; this.books.forEach(item =>{ sum += item.price*item.count; }) return sum; } } }); </script>
Summary of difficulties encountered
When the quantity is less than 0, there are many judgment methods and solutions. The following summarizes 3 methods
(1) The simplest method
Based on logical judgment, pay attention to the order of logical judgment here, the code is as follows:
Copy code The code is as follows:
(2) Pay attention here this points to the question
Copy code The code is as follows:
methods:{ min(index){ if(this.books[index].count>0){ this.books[index].count = parseInt(this.books[index].count) - 1; } }, deleteBook(book){ // vue 给我们提供了一个 $remove的方法,在数组中删除 this.books.$remove(book); /*this.books = this.books.filter((item)=>{ return item != book })*/ }, add(){ this.books.push(this.list); this.list = { name:'', price:'', count:'' } } }
(3) Parameter passing problem during v-on execution
Copy code The code is as follows:
min(book){ if(book.count>0){ book.count = parseInt(book.count) - 1; } }
Summary:
When v-on needs to pass parameters when executing a method, add (). If you don’t need to pass parameters, you don’t need to add ().
If you need to pass parameters, we You need to manually pass in the event source
Related recommendations:
Detailed steps for creating a book management platform using vue.js
Library management system source code php generates random verification code image code
Node.js close to actual combat (2) book management system_html/css_WEB-ITnose
The above is the detailed content of Vue implementation of book management examples. For more information, please follow other related articles on the PHP Chinese website!

Python中的支持向量机(SupportVectorMachine,SVM)是一个强大的有监督学习算法,可以用来解决分类和回归问题。SVM在处理高维度数据和非线性问题的时候表现出色,被广泛地应用于数据挖掘、图像分类、文本分类、生物信息学等领域。在本文中,我们将介绍在Python中使用SVM进行分类的实例。我们将使用scikit-learn库中的SVM模

Golang是一门功能强大且高效的编程语言,可以用于开发各种应用程序和服务。在Golang中,指针是一种非常重要的概念,它可以帮助我们更灵活和高效地操作数据。指针转换是指在不同类型之间进行指针操作的过程,本文将通过具体的实例来学习Golang中指针转换的最佳实践。1.基本概念在Golang中,每个变量都有一个地址,地址就是变量在内存中的位置。

随着新一代前端框架的不断涌现,VUE3作为一个快速、灵活、易上手的前端框架备受热爱。接下来,我们就来一起学习VUE3的基础知识,制作一个简单的视频播放器。一、安装VUE3首先,我们需要在本地安装VUE3。打开命令行工具,执行以下命令:npminstallvue@next接着,新建一个HTML文件,引入VUE3:<!doctypehtml>

随着互联网的普及,验证码已经成为了登录、注册、找回密码等操作的必要流程。在Gin框架中,实现验证码功能也变得异常简单。本文将介绍如何在Gin框架中使用第三方库实现验证码功能,并提供示例代码供读者参考。一、安装依赖库在使用验证码之前,我们需要安装一个第三方库goCaptcha。安装goCaptcha可以使用goget命令:$goget-ugithub

VAE是一种生成模型,全称是VariationalAutoencoder,中文译作变分自编码器。它是一种无监督的学习算法,可以用来生成新的数据,比如图像、音频、文本等。与普通的自编码器相比,VAE更加灵活和强大,能够生成更加复杂和真实的数据。Python是目前使用最广泛的编程语言之一,也是深度学习的主要工具之一。在Python中,有许多优秀的机器学习和深度

生成对抗网络(GAN,GenerativeAdversarialNetworks)是一种深度学习算法,它通过两个神经网络互相竞争的方式来生成新的数据。GAN被广泛用于图像、音频、文字等领域的生成任务。在本文中,我们将使用Python编写一个GAN算法实例,用于生成手写数字图像。数据集准备我们将使用MNIST数据集作为我们的训练数据集。MNIST数据集包含

随着互联网的迅速发展,数据已成为了当今信息时代最为重要的资源之一。而网络爬虫作为一种自动化获取和处理网络数据的技术,正越来越受到人们的关注和应用。本文将介绍如何使用PHP开发一个简单的网络爬虫,并实现自动化获取网络数据的功能。一、网络爬虫概述网络爬虫是一种自动化获取和处理网络资源的技术,其主要工作过程是模拟浏览器行为,自动访问指定的URL地址并提取所

快速上手Django框架:详细教程和实例引言:Django是一款高效灵活的PythonWeb开发框架,由MTV(Model-Template-View)架构驱动。它拥有简单明了的语法和强大的功能,能够帮助开发者快速构建可靠且易于维护的Web应用程序。本文将详细介绍Django的使用方法,并提供具体实例和代码示例,帮助读者快速上手Django框架。一、安装D


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
