moveUp() { if(this.clickNum !== this.getInfo.list.length){ this.clickNum++ console.log(this.clickNum); // 判断是否需要平移 if(this.clickNum > this.getInfo.list.length-3){ }else{ console.log('应该执行平移'); this.clickCount-= 190; } }else{ } }, moveDown(){ if(this.clickNum >0 ){ this.clickNum-- if(this.clickCount < 0){ this.clickCount+= 190 }else{ } } },这两个函数中,moveUp是向上平移,moveDown是向下平移,现在当moveUp的第一层条件再moveDown中被执行满足条件之后,moveup里的第二层if逻辑代码将不被执行,你修改一下让moveup里的第二层if逻辑代码可以一直能根据第一层if逻辑代码来执行,把你修改后的代码给我
时间: 2024-02-10 21:14:30 浏览: 18
可以将moveUp函数中的第二个if语句改为else if语句,这样就能够在第一个if语句执行之后,根据条件执行第二个if语句。修改后的代码如下:
```
moveUp() {
if (this.clickNum !== this.getInfo.list.length) {
this.clickNum++;
console.log(this.clickNum);
// 判断是否需要平移
if (this.clickNum > this.getInfo.list.length - 3) {
} else if (this.clickNum > 0) {
console.log('应该执行平移');
this.clickCount -= 190;
}
} else {
}
},
```
这样修改之后,当第一个if语句被执行之后,如果第二个if语句不满足条件,就会执行else if语句中的代码。
相关问题
if(this.clickNum !== this.getInfo.list.length){ this.clickNum++ console.log(this.clickNum); // 判断是否需要平移 if(this.clickNum > this.getInfo.list.length-3){ }else{ console.log('应该执行平移'); this.clickCount-= 190; // if(this.i <this.getInfo.list.length-1){ // this.i++ // } } }else{ }这段代码为什么第二层if else 判断再第一层if逻辑达成后不再执行。怎么可以让它一直根据第一层if逻辑来执行?用代码告诉我
第二层if-else语句在第一层if语句的条件为true时只会执行一次,因为它们在第一次执行后,clickNum的值已经等于list.length了。如果想让它们在每次第一层if语句满足条件时都执行一次,可以将clickNum的值重新设置为0。修改后的代码如下:
```
if(this.clickNum !== this.getInfo.list.length){
this.clickNum++;
console.log(this.clickNum);
// 判断是否需要平移
if(this.clickNum > this.getInfo.list.length-3){
}else{
console.log('应该执行平移');
this.clickCount-= 190;
// if(this.i <this.getInfo.list.length-1){
// this.i++
// }
}
}else{
// 重新设置clickNum的值为0
this.clickNum = 0;
}
```
}, created() { //this.bg(); let type = this.$route.query.type ? this.$route.query.type : ''; this.init(type); this.baseUrl = this.$config.baseUrl; this.ruleForm.fabushijian = this.getCurDateTime() }, methods: { getMakeZero(s) { return s < 10 ? '0' + s : s; }, // 下载 download(file){ window.open(`${file}`) }, // 初始化 init(type) { this.type = type; if(type=='cross'){ var obj = JSON.parse(localStorage.getItem('crossObj')); for (var o in obj){ if(o=='shipinmingcheng'){ this.ruleForm.shipinmingcheng = obj[o]; this.ro.shipinmingcheng = true; continue; } if(o=='shipinfengmian'){ this.ruleForm.shipinfengmian = obj[o].split(",")[0]; this.ro.shipinfengmian = true; continue; } if(o=='shipin'){ this.ruleForm.shipin = obj[o]; this.ro.shipin = true; continue; } if(o=='yonghuming'){ this.ruleForm.yonghuming = obj[o]; this.ro.yonghuming = true; continue; } if(o=='xingming'){ this.ruleForm.xingming = obj[o]; this.ro.xingming = true; continue; } if(o=='fabushijian'){ this.ruleForm.fabushijian = obj[o]; this.ro.fabushijian = true; continue; } if(o=='thumbsupnum'){ this.ruleForm.thumbsupnum = obj[o]; this.ro.thumbsupnum = true; continue; } if(o=='crazilynum'){ this.ruleForm.crazilynum = obj[o]; this.ro.crazilynum = true; continue; } if(o=='clicknum'){ this.ruleForm.clicknum = obj[o]; this.ro.clicknum = true; continue; } } }
这段代码是一个 Vue.js 组件的 created 钩子函数,用于初始化组件。在这个函数中,首先根据路由参数获取 type 值(如果没有则默认为空字符串),然后调用 init 方法进行初始化。在 init 方法中,根据 type 值判断是否为 cross 类型,然后从本地存储中读取 crossObj 对象,并解析其中的各个属性值,将其赋值给组件中对应的数据属性中。这个组件可能是用于发布视频信息的表单组件,其中包含了视频名称、封面、视频、用户信息等多个属性。