首页 > 解决方案 > 无法导航到 vue.js 中多页面表单中的下一页

问题描述

我无法导航到 vue.js 中多页面表单的下一页。

      name: 'xxx',
      data: ()=>{
         return{     
            currentPage: -1,
            text: "Hello"
         }
      },
  }         

在 vue 模板中绑定 CurrentPage,如下所示:

<div class="container" v-for="(pages, pageid) in pages_json" :currentPage="currentPage"  v-if="currentPage== pageid">

根据currentPage值,相应地显示表单。值从 -1 开始。每次点击vue.js 模板中的NEXT 按钮时,都需要更新 CurrentPage 。

this.$root.$validator.validate(scope + '.*').then(valid => {
  if (valid){
    if(text == "Hello"){
      this.currentPage += 1;
    }
    else{     
      // throwing error here, since assigning value to this.currentPage
      this.currentPage = 1;  

      console.log(this.currentPage)  // updating perfectly here                
    }
});

上面的代码用于在NEXT 按钮单击时调用的方法中。为 [else block] 内的 vue 数据赋值会引发错误。

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined"

标签: javascriptif-statementvue.js

解决方案


推荐阅读