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?
v-text="item.quantity || n "
html:
<code><!DOCTYPE html> <html lang="en"> <head> <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> </head> <body> <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="{{ url('/') }}">Laravel-cart</a> <ul class="nav nav-pills pull-right"> @if (Auth::guest()) <li class="nav-item"> <a class="nav-link" href="{{ url('/login') }}">login</a> </li> <li class="nav-item"> <a class="nav-link" href="{{ url('/register') }}">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="{{ url('/logout') }}"><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 class="card-header">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 "> //默認顯示從數(shù)據(jù)庫讀取的值,但是,當從下拉列表選擇的時候,需要顯示選擇的值,現(xiàn)在不能顯示。 </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <li v-for="n in nums"> <a class="dropdown-item" @click="fillIn(index, 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> </body> </html></code>
It’s really tiring to read this code on my phone...
v-model="items", wrong here;
v-model="items"
After ajax obtains the data, first manually add the required attributes selected, and then assign the value to items
selected
items
Undress images for free
AI-powered app for creating realistic nude photos
Online AI tool for removing clothes from photos.
AI clothes remover
Swap faces in any video effortlessly with our completely free AI face swap tool!
Easy-to-use and free code editor
Chinese version, very easy to use
Powerful PHP integrated development environment
Visual web development tools
God-level code editing software (SublimeText3)
TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource
PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti
TosettherighttimezoneinPHP,usedate_default_timezone_set()functionatthestartofyourscriptwithavalididentifiersuchas'America/New_York'.1.Usedate_default_timezone_set()beforeanydate/timefunctions.2.Alternatively,configurethephp.inifilebysettingdate.timez
TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout
ThePhpfunctionSerialize () andunserialize () AreusedtoconvertcomplexdaTastructdestoresintostoraSandaBackagain.1.Serialize () c OnvertsdatalikecarraysorobjectsraystringcontainingTypeandstructureinformation.2.unserialize () Reconstruct theoriginalatataprom
You can embed PHP code into HTML files, but make sure that the file has an extension of .php so that the server can parse it correctly. Use standard tags to wrap PHP code, insert dynamic content anywhere in HTML. In addition, you can switch PHP and HTML multiple times in the same file to realize dynamic functions such as conditional rendering. Be sure to pay attention to the server configuration and syntax correctness to avoid problems caused by short labels, quotation mark errors or omitted end labels.
The key to writing clean and easy-to-maintain PHP code lies in clear naming, following standards, reasonable structure, making good use of comments and testability. 1. Use clear variables, functions and class names, such as $userData and calculateTotalPrice(); 2. Follow the PSR-12 standard unified code style; 3. Split the code structure according to responsibilities, and organize it using MVC or Laravel-style catalogs; 4. Avoid noodles-style code and split the logic into small functions with a single responsibility; 5. Add comments at key points and write interface documents to clarify parameters, return values ??and exceptions; 6. Improve testability, adopt dependency injection, reduce global state and static methods. These practices improve code quality, collaboration efficiency and post-maintenance ease.
Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas