


This vuejs shopping cart demo cannot display the value of the selected drop-down list. Can anyone help me how to modify it?
In this vuejs shopping cart demo, in the v-text="item.quantity || n "
line, I don’t know how to display the value of the selected item in the drop-down list to the v-text of the button. Could someone help me how to modify it?
html:
<code> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="//cdn.bootcss.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet"> <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="//cdn.bootcss.com/tether/1.3.2/css/tether.min.css" rel="stylesheet"> <link href="//cdn.bootcss.com/tether/1.3.2/css/tether-theme-basic.min.css" rel="stylesheet"> <style> </style> <nav class="navbar navbar-light bg-faded"> <div class="container"> <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2"> ☰ </button> <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2"> <a class="navbar-brand cu_logo" href="%7B%7B%20url('/')%20%7D%7D">Laravel-cart</a> <ul class="nav nav-pills pull-right"> @if (Auth::guest()) <li class="nav-item"> <a class="nav-link" href="%7B%7B%20url('/login')%20%7D%7D">login</a> </li> <li class="nav-item"> <a class="nav-link" href="%7B%7B%20url('/register')%20%7D%7D">register</a> </li> @else <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">{{ Auth::user()->name }}</a> <div class="dropdown-menu"> <div class="dropdown-divider"></div> <a class="dropdown-item" href="%7B%7B%20url('/logout')%20%7D%7D"><i class="fa fa-btn fa-sign-out"></i>logout</a> </div> </li> @endif </ul> </div> </div> </nav> <div class="container"> <div class="card"> <h3 id="Cart">Cart</h3> <div class="card-block"> <div id="app"> <div class="row"> <div class="col-xs-2"> <label class="c-input c-checkbox"> <input type="checkbox" v-model="allSelected">Select All <span class="c-indicator"></span> </label> </div> <div class="col-xs-2"> Goods </div> <div class="col-xs-2"> Quantity </div> <div class="col-xs-2"> Unit Price </div> <div class="col-xs-2"> Subtotal </div> </div> <form> <div class="row" v-for="(index, item) in items"> <div class="col-xs-2"> <label class="c-input c-checkbox"> <input type="checkbox" v-model="item.selected" :value="item.id"> <span class="c-indicator"></span> </label> </div> <div class="col-xs-2"> @{{ item.name }} </div> <div class="col-xs-2"> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-text="item.quantity || n "> //默认显示从数据库读取的值,但是,当从下拉列表选择的时候,需要显示选择的值,现在不能显示。 </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <li v-for="n in nums"> <a class="dropdown-item" n>@{{ n }}个</a> //下拉列表 </li> </ul> </div> </div> <div class="col-xs-2"> @{{ item.unit_price }} </div> <div class="col-xs-2"> @{{ item.unit_price * item.quantity }} </div> </div> <div class="row"> <div class="col-xs-3"> Sum </div> <div class="col-xs-5"> </div> <div class="col-xs-2"> @{{ sum }} </div> </div> <button type="submit" class="btn btn-primary" :disabled="sum === 0">Submit</button> </form> </div> </div> </div> </div> <script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> <script src="//cdn.bootcss.com/tether/1.3.2/js/tether.min.js"></script> <script src="//cdn.bootcss.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script> <script src="//cdn.bootcss.com/vue/1.0.24/vue.min.js"></script> <script src="//cdn.bootcss.com/vue-resource/0.7.3/vue-resource.min.js"></script> <script type="text/javascript"> Vue.config.debug = true; var vm = new Vue({ el: "#app", data: { items: [] }, ready: function () { this.$http.get('/api/cart').then(function (response) { response.data.forEach(function (item) { item.selected = false; }); vm.items = response.data; }, function (response) { // error callback }); }, methods: { fillIn: function (index, n) { this.items[index].num = n; } }, computed: { nums: function () { return [1, 2, 3, 4, 5]; }, allSelected: { get: function () { for (var i = 0, length = this.items.length; i < length; i++) { if (this.items[i].selected === false) { return false; } } return true; }, set: function (val) { for (var i = 0, length = this.items.length; i < length; i++) { this.items[i].selected = val; } } }, sum: function () { var totalAmount = 0; for (var i = 0, length = this.items.length; i < length; i++) { var item = this.items[i]; if (item.selected === true) { totalAmount += item.unit_price * item.quantity; } } return totalAmount; } } }); </script> </code>
Reply content:
In this vuejs shopping cart demo, in the v-text="item.quantity || n "
line, I don’t know how to display the value of the selected item in the drop-down list to the v-text of the button. Could someone help me how to modify it?
html:
<code> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="//cdn.bootcss.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" rel="stylesheet"> <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"> <link href="//cdn.bootcss.com/tether/1.3.2/css/tether.min.css" rel="stylesheet"> <link href="//cdn.bootcss.com/tether/1.3.2/css/tether-theme-basic.min.css" rel="stylesheet"> <style> </style> <nav class="navbar navbar-light bg-faded"> <div class="container"> <button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#exCollapsingNavbar2"> ☰ </button> <div class="collapse navbar-toggleable-xs" id="exCollapsingNavbar2"> <a class="navbar-brand cu_logo" href="%7B%7B%20url('/')%20%7D%7D">Laravel-cart</a> <ul class="nav nav-pills pull-right"> @if (Auth::guest()) <li class="nav-item"> <a class="nav-link" href="%7B%7B%20url('/login')%20%7D%7D">login</a> </li> <li class="nav-item"> <a class="nav-link" href="%7B%7B%20url('/register')%20%7D%7D">register</a> </li> @else <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">{{ Auth::user()->name }}</a> <div class="dropdown-menu"> <div class="dropdown-divider"></div> <a class="dropdown-item" href="%7B%7B%20url('/logout')%20%7D%7D"><i class="fa fa-btn fa-sign-out"></i>logout</a> </div> </li> @endif </ul> </div> </div> </nav> <div class="container"> <div class="card"> <h3 id="Cart">Cart</h3> <div class="card-block"> <div id="app"> <div class="row"> <div class="col-xs-2"> <label class="c-input c-checkbox"> <input type="checkbox" v-model="allSelected">Select All <span class="c-indicator"></span> </label> </div> <div class="col-xs-2"> Goods </div> <div class="col-xs-2"> Quantity </div> <div class="col-xs-2"> Unit Price </div> <div class="col-xs-2"> Subtotal </div> </div> <form> <div class="row" v-for="(index, item) in items"> <div class="col-xs-2"> <label class="c-input c-checkbox"> <input type="checkbox" v-model="item.selected" :value="item.id"> <span class="c-indicator"></span> </label> </div> <div class="col-xs-2"> @{{ item.name }} </div> <div class="col-xs-2"> <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-text="item.quantity || n "> //默认显示从数据库读取的值,但是,当从下拉列表选择的时候,需要显示选择的值,现在不能显示。 </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <li v-for="n in nums"> <a class="dropdown-item" n>@{{ n }}个</a> //下拉列表 </li> </ul> </div> </div> <div class="col-xs-2"> @{{ item.unit_price }} </div> <div class="col-xs-2"> @{{ item.unit_price * item.quantity }} </div> </div> <div class="row"> <div class="col-xs-3"> Sum </div> <div class="col-xs-5"> </div> <div class="col-xs-2"> @{{ sum }} </div> </div> <button type="submit" class="btn btn-primary" :disabled="sum === 0">Submit</button> </form> </div> </div> </div> </div> <script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> <script src="//cdn.bootcss.com/tether/1.3.2/js/tether.min.js"></script> <script src="//cdn.bootcss.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js"></script> <script src="//cdn.bootcss.com/vue/1.0.24/vue.min.js"></script> <script src="//cdn.bootcss.com/vue-resource/0.7.3/vue-resource.min.js"></script> <script type="text/javascript"> Vue.config.debug = true; var vm = new Vue({ el: "#app", data: { items: [] }, ready: function () { this.$http.get('/api/cart').then(function (response) { response.data.forEach(function (item) { item.selected = false; }); vm.items = response.data; }, function (response) { // error callback }); }, methods: { fillIn: function (index, n) { this.items[index].num = n; } }, computed: { nums: function () { return [1, 2, 3, 4, 5]; }, allSelected: { get: function () { for (var i = 0, length = this.items.length; i < length; i++) { if (this.items[i].selected === false) { return false; } } return true; }, set: function (val) { for (var i = 0, length = this.items.length; i < length; i++) { this.items[i].selected = val; } } }, sum: function () { var totalAmount = 0; for (var i = 0, length = this.items.length; i < length; i++) { var item = this.items[i]; if (item.selected === true) { totalAmount += item.unit_price * item.quantity; } } return totalAmount; } } }); </script> </code>
It’s really tiring to read this code on my phone...
v-model="items"
, wrong here;After ajax obtains the data, first manually add the required attributes
selected
, and then assign the value toitems

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


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

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),

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.

Atom editor mac version download
The most popular open source editor

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

SublimeText3 Chinese version
Chinese version, very easy to use
