Javascript 升级vuejs应用程序时如何解决此错误?

Javascript 升级vuejs应用程序时如何解决此错误?,javascript,vue.js,Javascript,Vue.js,我有一个旧的vuejs应用程序,我正在尝试从1.0.28升级到2.5.16 以下代码不适用于2.5.16,但适用于1.0.28 html <a class="button" v-on:click="selectPage(this.pagination.currentPage-1)" v-bind:class="{'is-disabled': this.pagination.currentPage==this.pagination.items

我有一个旧的vuejs应用程序,我正在尝试从1.0.28升级到2.5.16

以下代码不适用于2.5.16,但适用于1.0.28

html

<a class="button" v-on:click="selectPage(this.pagination.currentPage-1)" v-bind:class="{'is-disabled': this.pagination.currentPage==this.pagination.items[0] || this.pagination.items.length==0}">Previous</a>
<a class="button" v-on:click="selectPage(this.pagination.currentPage+1)" v-bind:class="{'is-disabled': this.pagination.currentPage==this.pagination.items[this.pagination.items.length-1] || this.pagination.items.length==0}">Next page</a>
上一个
下一页
方法

selectPage(item) {
      this.pagination.currentPage = item
      
      let start = 0
      let end = 0
      if(this.pagination.currentPage < this.pagination.range-2){
        start = 1
        end = start+this.pagination.range-1
      }
      else if(this.pagination.currentPage <= this.pagination.items.length && this.pagination.currentPage > this.pagination.items.length - this.pagination.range + 2){
        start = this.pagination.items.length-this.pagination.range+1
        end = this.pagination.items.length
      }
      else{
        start = this.pagination.currentPage-2
        end = this.pagination.currentPage+2
      }
      if(start<1){
        start = 1
      }
      if(end>this.pagination.items.length){
        end = this.pagination.items.length
      }
      
      this.pagination.filteredItems = []
      for(var i=start; i<=end; i++){
        this.pagination.filteredItems.push(i);
      }
      
      this.paginatedItems = this.filteredItems.filter((v, k) => {
        return Math.ceil((k+1) / this.pagination.itemPerPage) == this.pagination.currentPage
      })
    },
选择页面(项目){
this.pagination.currentPage=项目
让我们开始=0
设end=0
if(this.pagination.currentPage
我在控制台中看到以下错误:

Uncaught TypeError: Cannot read property 'currentPage' of undefined
    at click (eval at createFunction (vue.js:10667), <anonymous>:3:1514)
    at invoker (vue.js:2029)
    at HTMLAnchorElement.fn._withTask.fn._withTask (vue.js:1828)
Uncaught TypeError:无法读取未定义的属性“currentPage”
单击时(在createFunction(vue.js:10667)处求值):3:1514)
调用程序(vue.js:2029)
在htmlanchoreElement.fn._withTask.fn._withTask(vue.js:1828)
我如何让它与vue 2.5.16配合使用

解决方案 更改为:

<a class="button" v-on:click="selectPage(pagination.currentPage-1)" v-bind:class="{'is-disabled': pagination.currentPage==this.pagination.items[0] || this.pagination.items.length==0}">Previous</a>
    <a class="button" v-on:click="selectPage(pagination.currentPage+1)" v-bind:class="{'is-disabled': pagination.currentPage==this.pagination.items[this.pagination.items.length-1] || this.pagination.items.length==0}">Next page</a>
上一个
下一页

此.pagination.currentPage
替换为模板中的
pagination.currentPage

显示定义
分页的位置。