基于iview admin二次开发,tables列描述数据对象type属性使用注意事项


type属性:选值为 index、selection、expand、html

基于iview admin二次开发,tables列描述数据对象type属性使用注意事项

现象:

当一列或多列的type属性为 index、selection、expand、html时,出现如下错误:

vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in callback for watcher "value": "TypeError: Cannot read property 'indexOf' of undefined"

found in

---> <Tables>
  <Card>
    <Anonymous>
      <Content>
        <Layout>
          <Content>
            <Layout>... (1 recursive calls)
              <Main> at src/components/main/main.vue
                <App> at src/App.vue
                  <Root>

vue.runtime.esm.js?2b0e:1737 TypeError: Cannot read property 'indexOf' of undefined
  at eval (tables.vue?b476:216)
  at Array.filter (<anonymous>)
  at VueComponent.handleSearch (tables.vue?b476:215)
  at VueComponent.value (tables.vue?b476:268)
  at Watcher.run (vue.runtime.esm.js?2b0e:3229)
  at flushSchedulerQueue (vue.runtime.esm.js?2b0e:2977)
  at Array.eval (vue.runtime.esm.js?2b0e:1833)
  at flushCallbacks (vue.runtime.esm.js?2b0e:1754)

原因:

  tables的搜索功能,加载列名称的代码如下:

  setDefaultSearchKey () {

      this.searchKey = this.columns[0].key !== 'handle' ? this.columns[0].key : (this.columns.length > 1 ? this.columns[1].key : '')

  }
列属性key非'handle'时,为搜索项目,当加入type属性,搜索就报错

解决方法:

1.若仅一列的type属性为 index、selection、expand、html时,此列添加key:'handle',即{type:'index',key:'handle',title: '序号', width: 60, align: 'center' }
2.若多列的type属性为 index、selection、expand、html时,
  此列添加key:'handle',{type:'index',key:'handle',title: '序号', width: 60, align: 'center' }
  且修改 ...\src\components\tables\tables.vue
  handleSearch () {
    //添加此判断
  if(this.searchKey.indexOf('handle')>-1){
  return false
  }
  this.insideTableData = this.value.filter(item => item[this.searchKey].indexOf(this.searchValue) > -1)
  }
问题完美解决


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM