vue中v-for的用法以及参数的作用
2024-08-24 06:37:59
<template>
<div>
<div class="content clearfix" v-on:click="goorderingDetail(v)" v-for="(v,index) in anylist" :key="index">
<div class="clearfix">
<div class="fl dingnumber">订单号 <span>{{v.orderNum}}</span></div>
<div class="fr state">{{v.state}}</div>
</div>
<div class="clearfix receive">
<div class="fl">收</div>
<div class="fr add reAdd">{{v.receiveAdd}}</div>
</div>
<div class="clearfix send">
<div class="fl">发</div>
<div class="fr add sAdd">{{v.sendAdd}}</div>
</div>
<div class="date fl">2018年9月28日 12:00</div>
<div class="fr sure" v-on:click.stop="gosureReceive(v)">确认取件</div>
</div>
</div>
</template> <script>
import $ from 'jquery'
export default {
name: 'ordering',
data () {
return {
anylist: []
}
},
mounted () {
this.ready()
},
methods: {
ready: function () {
$.ajax({
type: 'GET',
url: './../../../static/ing.json',
data: {},
dataType: 'json'
}).then(res => {
// console.log(res)
// console.log(res.data)
this.anylist = res.data
})
.catch(error => {
console.log(error)
})
},
goorderingDetail: function (v) {
// console.log(v.receiveAdd)
// console.log(v.sendAdd)
/* 获取当前点击内容的收件发件地址 */
var IreAdd = v.receiveAdd
var IseAdd = v.sendAdd
var IOrderNum = v.orderNum
sessionStorage.setItem('IReAdd', JSON.stringify(IreAdd))
sessionStorage.setItem('ISeAdd', JSON.stringify(IseAdd))
sessionStorage.setItem('IOrderNum', JSON.stringify(IOrderNum))
this.$router.push({path: '/orderingDetail'})
},
gosureReceive: function (v) {
// console.log(v.receiveAdd)
// console.log(v.sendAdd)
/* 获取当前点击内容的收件发件地址 */
var IreAdd = v.receiveAdd
var IseAdd = v.sendAdd
sessionStorage.setItem('IReAdd', JSON.stringify(IreAdd))
sessionStorage.setItem('ISeAdd', JSON.stringify(IseAdd))
this.$router.push({path: '/sureReceive'})
}
}
}
</script> <style scoped>
.content{
width: 96%;
margin: auto;
padding: 0.3rem;
background: #ffffff;
box-shadow: 5px 5px 5px #eae8e8;
margin-top: 0.5rem;
}
.dingnumber{
font-size: 0.8rem;
line-height: 1.7rem;
}
.state{
font-size: 1rem;
letter-spacing: 1px;
color: #ff7c1d;
margin-right: 0.5rem;
font-weight: bold;
}
.receive,.send{
font-size: 0.9rem;
font-weight: bold;
color: #ff7c1d;
margin-top: 1rem;
}
.add{
width: 85%;
vertical-align: bottom;
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ;需与overflow:hidden;一起使用。*/
}
.date{
text-align: left;
font-size: 0.8rem;
padding: 0.2rem;
margin-top: 2rem;
}
.sure{
padding: 0.5rem 1rem 0.5rem 1rem;
border: 1.5px solid #ff7c1d;
letter-spacing: 1px;
border-radius: 0.3rem;
margin-top: 0.9rem;
margin-right: 0.3rem;
font-weight: bold;
color: #ff7c1d;
font-size: 0.9rem;
z-index: 1000;
}
</style>
上面代码中,第3行和第17行:
第3行和第17行函数都包含在v-for循环中,参数中传入的参数v都可以获取到数据集合
第50和第62行在函数中传入v即可获取到对应的值(但是需要在定义函数和使用函数时都传入参数v才能用)
最新文章
- ASP.NET MVC Model验证(三)
- BZOJ 2438: [中山市选2011]杀人游戏
- 字符模型和Windows等价程序
- asp.net mvc4使用百度ueditor编辑器
- PostgreSQL的创建表
- 低功耗之战!ANT VS Bluetooth LE
- 小测试 php代理,nginx代理,直接访问对比
- (64位oracle使用32位的PLSQL)安装64位的oracle数据库软件,使用32位的PLSQL Developer连接方法
- xamarin Android activity生命周期详解
- java遍历Map
- 批量数据的Excel导入
- [Demo_01] MapReduce 实现密码 Top10 统计
- Spark算子讲解(二)
- pandas与sqlalchemy交互实现科学计算
- (转载)C#工具箱Menustrip控件中分割线的设置方法
- java 数据导入xls
- C++STL 算法
- LinkedBlockQueue生产消费源码解析
- Asp.net单点登录解决方案
- python学习(十六)写爬虫爬取糗事百科段子