基於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