vue.js - 如何跳过第三步跳到第四步
问题描述
这里我在 vue.js 中编写了代码。我试图跳过第三步到第四步。就像我们正在导航多步表单一样,我们处于第二步,如果我们按下一步按钮从第二步开始,那么它应该直接导航到第四步。表示跳过第三步。因此,如果有人有想法请帮助我,我正在努力实现这一目标
<div id="app">
<form>
<div v-if="step === 1">
<h1>Step One</h1>
<p>
<legend for="name">Your Name:</legend>
<input id="name" name="name" v-model="registration.name">
</p>
<p>
<legend for="email">Your Email:</legend>
<input id="email" name="email" type="email" v-model="registration.email">
</p>
<button @click.prevent="next()">Next</button>
</div>
<div v-if="step === 2">
<h1>Step Two</h1>
<p>
<legend for="street">Your Street:</legend>
<input id="street" name="street" v-model="registration.street">
</p>
<p>
<legend for="city">Your City:</legend>
<input id="city" name="city" v-model="registration.city">
</p>
<p>
<legend for="state">Your State:</legend>
<input id="state" name="state" v-model="registration.state">
</p>
<button @click.prevent="prev()">Previous</button>
<button @click.prevent="next()">Next</button>
</div>
<div v-if="step === 3">
<h1>Step Three</h1>
<p>
<legend for="numtickets">Number of Tickets:</legend>
<input id="numtickets" name="numtickets" type="number" v-model="registration.numtickets">
</p>
<p>
<legend for="shirtsize">Shirt Size:</legend>
<select id="shirtsize" name="shirtsize" v-model="registration.shirtsize">
<option value="S">Small</option>
<option value="M">Medium</option>
<option value="L">Large</option>
<option value="XL">X-Large</option>
</select>
</p>
<button @click.prevent="prev()">Previous</button>
<button @click.prevent="next()">Next</button>
</div>
<div v-if="step === 4">
<h1>Step Four</h1>
<button @click.prevent="prev()">Previous</button>
<button @click.prevent="next()">Next</button>
</div>
<div v-if="step === 5">
<h1>Step Five</h1>
<button @click.prevent="prev()">Previous</button>
<button @click.prevent="submit()">Save</button>
</div>
</form>
</div>
Vue.js
<script>
const app = new Vue({
el:'#app',
data() {
return {
step:1,
registration:{
name:null,
email:null,
street:null,
city:null,
state:null,
numtickets:0,
shirtsize:'XL'
}
}
},
methods:{
prev() {
this.step--;
},
next() {
this.step++;
},
submit() {
alert('Submit to blah and show blah and etc.');
}
}
});
</script>
解决方案
您可以通过分配所需的页面来轻松实现它:
this.step = 4 // or another site you want to set
在函数中传递一个参数next()
:
<button @click.prevent="next(3)">Next</button>
next(currentStep) {
if (currentStep === 3) {
this.step = 4 // jump from step 2 to step 4
} else {
this.step++;
}
}
作为一个快速的建议
更新导航回来:
<button @click.prevent="prev(4)">Previous</button>
prev(currentStep) {
if (currentStep === 4) {
this.step = 2 // jump from step 4 to step 2
} else {
this.step--
}
}
推荐阅读
- javascript - 在模态引导程序中向前和向后移动不起作用
- angular - 如何使用由 Wordpress 插件生成的 OAuth 隐式授予访问令牌在 Firebase 上对用户进行身份验证?
- c# - 从列表中选择没有标识符
- javascript - 仅在 Angular 8 中获得表单提交响应后才显示模式
- rust - 返回异步移动块中的任何内容
- excel - 获取 youtube 视频的成绩单
- html - 更改引导日期选择器位置不起作用
- python - IndentationError:无缘无故的意外取消缩进
- c - C语言中的换行符从何而来?
- vba - 应计时间计算转到 48 小时而不是 24 小时 EXCEL VBA