


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><!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 "> //默认显示从数据库读取的值,但是,当从下拉列表选择的时候,需要显示选择的值,现在不能显示。 </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>
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><!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 "> //默认显示从数据库读取的值,但是,当从下拉列表选择的时候,需要显示选择的值,现在不能显示。 </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;After ajax obtains the data, first manually add the required attributes
selected
, and then assign the value toitems

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











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Vue.js is suitable for small and medium-sized projects and fast iterations, while React is suitable for large and complex applications. 1) Vue.js is easy to use and is suitable for situations where the team is insufficient or the project scale is small. 2) React has a richer ecosystem and is suitable for projects with high performance and complex functional needs.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
