search

Home  >  Q&A  >  body text

javascript - ant design 菜单从接口里面获取 怎么写?现在都是写死的

菜单是动态从接口里面读取的,但是不知道怎么写 module.exports ,不知道怎么在ajax里面写module.exports

const func = function () {
  let  $d = {};
  $d.opId = Cookie.get('user_id');
  $d.tokens = Cookie.get('tokens');
  Ajax.ajax({
    url: Config.api+"/menu/queryAllMenuList",
    method:"post",
    data:$d,
    //processData: options.method === 'get',
    dataType: 'JSON',
  }).done((data) => {
    return [];
  })
};

ringa_leeringa_lee2786 days ago331

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 16:33:58

    The acquired data is assembled into a structure that can be recognized by the antd component. For example, does the dataSource attribute of table recognize an array?

    reply
    0
  • 黄舟

    黄舟2017-04-17 16:33:58

    Encapsulate ajax into a function, call this function and get the value of ajax.
    The rest is a matter of manipulating data.

    ajax is asynchronous, so module.exports cannot get the value of ajax.

    reply
    0
  • 阿神

    阿神2017-04-17 16:33:58

    Call ajax in the module, set a state, change the value of the state after the callback is successful, and then assemble it into an antd component in render

    class Demo extends React.Component {
        constructor(){
            this.state = {
                data: []
            }
        }
        componentWillMount(){
            //...
            Ajax.ajax({
                url: Config.api+"/menu/queryAllMenuList",
                method:"post",
                data:$d,
                //processData: options.method === 'get',
                dataType: 'JSON',
              }).done((data) => {
                this.setState({
                    data: data
                })
              })
              //....
        }
        render() {
            //使用this.state.data作为数据写antdesign的组件
        }
    }
    
    export default Demo;

    reply
    0
  • Cancelreply