vuejs2 - 在 Vue.js 中循环数据
问题描述
我有三个列表项,我正在尝试使用Vue.js
. 显示单个项目时它工作正常,但是当我尝试显示多个项目时它不起作用。 代码笔链接
var data = {
products : [
{
"id": "532",
"name": "Bamboo Thermal Ski Coat",
"description": "You'll be the most environmentally conscious skier on the slopes - and the most stylish wearing our fitted bamboo thermal ski coat, made from organic bamboo with recycled plastic down filling. ",
"image": "https://cdn.shopify.com/s/files/1/0133/3248/0100/products/JAYCOSIN-Women-s-Coat-Fashion-Womens-Ladies-Warm-Faux-Fur-Comfortable-Coat-Sexy-Jacket-Winter-Solid_2048x2048.jpg?v=1574355729",
"price": "99"
},
{
"id": "532",
"name": "Bamboo Thermal Ski Coat",
"description": "You'll be the most environmentally conscious skier on the slopes - and the most stylish wearing our fitted bamboo thermal ski coat, made from organic bamboo with recycled plastic down filling. ",
"image": "https://cdn.shopify.com/s/files/1/0133/3248/0100/products/JAYCOSIN-Women-s-Coat-Fashion-Womens-Ladies-Warm-Faux-Fur-Comfortable-Coat-Sexy-Jacket-Winter-Solid_2048x2048.jpg?v=1574355729",
"price": "99"
},
{
"id": "532",
"name": "Bamboo Thermal Ski Coat",
"description": "You'll be the most environmentally conscious skier on the slopes - and the most stylish wearing our fitted bamboo thermal ski coat, made from organic bamboo with recycled plastic down filling. ",
"image": "https://cdn.shopify.com/s/files/1/0133/3248/0100/products/JAYCOSIN-Women-s-Coat-Fashion-Womens-Ladies-Warm-Faux-Fur-Comfortable-Coat-Sexy-Jacket-Winter-Solid_2048x2048.jpg?v=1574355729",
"price": "99"
}
]
}
var app = new Vue({
el: "#app",
data: data
});
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div class="container" id="app">
<div class="row d-flex mb-3 align-item-center" v-for="item in products">
<div class="col-sm-4">
<a :href="href">
<img class="img-fluid" :src="item.image" :alt="item.name" width="250" height="300">
</a>
</div>
<div class="col">
<h3 class="text-info">{{ item.name}}</h3>
<p class="mb-0">{{ item.description}}</p>
<div class="h5 float-right">$ {{item.price}}</div>
</div>
</div>
解决方案
<a :href="href">
正在访问一个未定义的变量 (href)
使用<a :href="item.href">
然后添加href
到每个项目。
推荐阅读
- python - 如何全局编辑变量python
- android - Android:停止前台服务导致应用程序崩溃
- c# - 动态对象不包含来自引用的属性定义
- vue.js - 在 webcomponent 构建中使用插槽时,VueJS $children 为空
- node.js - 为什么在 Node.js 中使用猫鼬模式
- python - 按行中的值从熊猫数据透视表中过滤
- machine-learning - 尝试调用函数时 Octave 中的错误:第 1 行第 1 列附近未定义
- node.js - Mongoose 全文搜索未正确过滤
- php - 将域从 DO 帐户 droplet 移动到另一个 DO 帐户 droplet
- .net-core - 在 Blazor 中筛选分页列表