Vue.js Vuejs 2:无法在选项卡式表单之间切换
我正在使用Vue2构建基于选项卡的表单。我在我的main.js中使用Vue.js Vuejs 2:无法在选项卡式表单之间切换,vue.js,vuejs2,Vue.js,Vuejs2,我正在使用Vue2构建基于选项卡的表单。我在我的main.js中使用 从“vue表单向导”导入VueFormWizard 导入“vue表单向导/dist/vue表单向导.min.css” Vue.use(VueFormWizard) 从“vee validate”导入vee validate Vue.use(VeeValidate) 文件AddUser.vue包含以下代码: 从“sweetalert”导入swal 导出默认值{ 方法:{ validateFirstTab:函数(){ 这是
- 从“vue表单向导”导入VueFormWizard
- 导入“vue表单向导/dist/vue表单向导.min.css”
- Vue.use(VueFormWizard)
- 从“vee validate”导入vee validate
- Vue.use(VeeValidate)
从“sweetalert”导入swal
导出默认值{
方法:{
validateFirstTab:函数(){
这是。$validator.validateAll()。然后((结果)=>{
如果(结果){
返回
}
swal('输入字段验证','请更正错误!','错误')
})
}
}
}
添加新用户
名称
{{errors.first('name')}
验证程序承诺中缺少返回值。vue表单向导beforeChange
函数应为布尔值
这是选项卡content
组件的beforeChange
prop
/***
* Function to execute before tab switch. Return value must be boolean
* If the return result is false, tab switch is restricted
*/
beforeChange: {
type: Function
},
以下是承诺解决后实际发生的情况
validateBeforeChange (promiseFn, callback) {
this.setValidationError(null)
// we have a promise
if (isPromise(promiseFn)) {
this.setLoading(true)
promiseFn.then((res) => {
// ^^^
// res is undefined because there is no return value in your case,
// error is catched later on.
//
this.setLoading(false)
let validationResult = res === true
this.executeBeforeChange(validationResult, callback)
}).catch((error) => {
this.setLoading(false)
this.setValidationError(error)
})
// we have a simple function
} else {
let validationResult = promiseFn === true
this.executeBeforeChange(validationResult, callback)
}
},
请尝试以下操作:
<script>
import swal from 'sweetalert'
export default {
methods: {
validateFirstTab: function () {
this.$validator.validateAll().then((result) => {
if (result) {
return true
}
swal('Input Field(s) Validation', 'Please correct the errors!', 'error')
return false
})
}
}
}
</script>
从“sweetalert”导入swal
导出默认值{
方法:{
validateFirstTab:函数(){
这是。$validator.validateAll()。然后((结果)=>{
如果(结果){
返回真值
}
swal('输入字段验证','请更正错误!','错误')
返回错误
})
}
}
}