拿数据报错0没有定义

问题描述

mock数据拿对象没问题加上数组[0]就报错0没有定义

问题出现的环境背景及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

 'GET /api/v1/base/ADpage':{
    "userMessage":{
      img:'http://img.ad.guideinchina.com/FmEHxKa-McrhxLN59lXywvoIgeWC',
      userid:'12',
      name:'Owee',
      mobile:'13112341234',
      balance:123
    },
    "amMessage":{
      img:'http://img.ad.guideinchina.com/FmEHxKa-McrhxLN59lXywvoIgeWC',
      linkman:'lulu',
      wechat:'wang46327',
      mobile:'13488884444'
    },
    "list":{
      img:'http://img.ad.guideinchina.com/FmEHxKa-McrhxLN59lXywvoIgeWC',
      today:[{
        pageviews:33,
        uniquevisitor:15,
        IPnumber:32,
        bouncerate:23,
        spend:22,
        bidamount:20
      }],
      yesterday:[{
        pageviews:33,
        uniquevisitor:15,
        IPnumber:32,
        bouncerate:23,
        spend:22,
        bidamount:20
      }],
      anteayer:[{
        pageviews:33,
        uniquevisitor:15,
        IPnumber:32,
        bouncerate:23,
        spend:22,
        bidamount:20
      }]
    }
  },

你期待的结果是什么?实际看到的错误信息又是什么?

list.today浏览器能看到数据
list.today[0].pageviews就0没有定义怎么回事?

放页面代码吧..

import React from 'react';
import { Table  } from 'antd';
import { connect } from 'dva';
import intl from "react-intl-universal";
import { string } from 'util_react_web';

const { getIntl } = string;
@connect(({ adpage }) => ({
  adpage,
}))
class Tablee extends React.Component {
  state = {
  };

  componentDidMount(){
    const { dispatch } = this.props;
    dispatch({
      type:'adpage/getadpage',
    });

  }

  render() {
    const { adpage} = this.props;
    console.log(adpage);
    const {list} = adpage;
    console.log(list.today[0]);
    // console.log(list.today[0].pageviews);
    
    const columns = [{
      title: `${getIntl(intl, 'AD.body.date', 'Date' )}`,
      dataIndex: 'date',
    }, {
      title: `${getIntl(intl, 'AD.body.date', 'Pageviews' )}`,
      dataIndex: 'pv',
    }, {
      title: `${getIntl(intl, 'AD.body.uv', 'Unique visitor' )}`,
      dataIndex: 'uv',
    }
    , {
      title: `${getIntl(intl, 'AD.body.ipnumber', 'IP number' )}`,
      dataIndex: 'ip',
    }, {
      title: `${getIntl(intl, 'AD.body.bouncerate', 'Bounce Rate' )}`,
      dataIndex: 'jomp',
    }, {
      title: `${getIntl(intl, 'AD.body.spend', 'Spend' )}`,
      dataIndex: 'spend',
    },{
      title:  `${getIntl(intl, 'AD.body.bidAmount', 'Bid amount' )}`,
      dataIndex: 'moyne',
    }];
    const data = [{
      key: '1',
      date: `${getIntl(intl, 'AD.body.Today', 'Today' )}`,
      pv: list.today[0].pageviews,
      uv: '15',
      ip:'34',
      jomp:'23',
      spend:22,
      moyne:'20'
    }, {
      key: '2',
      date: `${getIntl(intl, 'AD.body.Yesterday', 'Yesterday' )}`,
      pv: 42,
      uv: '12',
      ip:'34',
      jomp:'23',
      spend:22,
      moyne:'20'
    }, {
      key: '3',
      date:  `${getIntl(intl, 'AD.body.Anteayer', 'Anteayer' )}`,
      pv: 32,
      uv: '32',
      ip:'34',
      jomp:'23',
      spend:22,
      moyne:'20'
    }];
   
    return (
      <div>
       
        <Table 
          style={{textAlignLast:"center"}}
          pagination={false} 
          columns={columns} 
          dataSource={data}
          size="small "
          align="center"
        />
      
      </div>
    );
  }
}
export default Tablee;

models层

import { getAdpage } from '../services/adpage';


export default {
    namespace: 'adpage',
    state: {
      userMessage: {},
      amMessage:{},
      list:{}
    },
    reducers: {
      save(state, { payload: { userMessage,amMessage,list }}) {
        return { ...state, userMessage ,amMessage,list};
      },
      // saveList(state, { payload: { list, groupList }}) {
      //   return { ...state, list, groupList };
      // },
    },
    effects: {
      *getadpage(_, { call, put }) {
        const adpage = yield call(getAdpage)
        const { userMessage , amMessage,list } = adpage
        
        yield put({ type: 'save', payload: {userMessage,amMessage,list} });
      },
    },
    // 监听路径
    subscriptions:{
      setup({dispatch,history}){
          return history.listen(({pathname,userMessage,amMessage,list})=>{
            if(pathname === "/AD/ADpage"){
              dispatch({type:'getone',payload: {userMessage,amMessage,list}})
            }
          })
      }
    }
  }
阅读 1.9k
1 个回答

list 是数组还是 list.today 是数组?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题