我现在要实现的是v-for每次按2条项目这样来循环,里面有函数是处理index,可是会出现符合的index重复调用的情况。
template:
scrip:
let count = 3
let indexArr = []
export default {
name: 'reportPage',
data () {
return {
tdata: [1,2,3],
myForm: {
'myCompany': '海南凯迪网络资讯股份有限公司',
'myTips': ''
},
totalPage: 4,
}
},
mounted () {
let that = this
let height = document.body.clientHeight - 60
that.$refs.main.style.height = height+'px'
// alert(((that.tdata.length - 1)%2))
if (that.tdata.length === 1 ) {
that.totalPage = 4
}else {
that.totalPage = 4 + Math.floor((that.tdata.length - 1)/2) + 1
}
// alert(that.totalPage)
// if ((that.tdata.length%2) && tdata.length>1) {
// that.totalPage = 3 + that.tdata.length + 1
// }else{
// that.totalPage = 3 + that.tdata.length
// }
},
methods: {
submitForm (e) {
let that = this
e.preventDefault()
that.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
})
},
textChange () {
let that = this
// console.log('tips==',that.form.getFieldValue('tips'))
that.myForm.myTips = that.form.getFieldValue('tips')
},
getPageNum (index) {
console.log("index=", index)
// console.log("count1=",count)
// if (indexArr.indexOf(index) == -1) {
// indexArr.push(index)
// count--
// }
// console.log("count2==",count)
// console.log('sum=', index + count)
// return index + count
}
}
}
打印的结果:
有谁遇到同样的问题吗?我想要的结果是打印出来的index不是重复执行的,就是执行一次。