Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

异步加载菜单 #9

Closed
youxiaodao opened this issue Sep 12, 2019 · 1 comment
Closed

异步加载菜单 #9

youxiaodao opened this issue Sep 12, 2019 · 1 comment

Comments

@youxiaodao
Copy link

请问,异步加载菜单的方法里面该如何引入ajax请求后端菜单?
使用文档中推荐的三种方式,都会报错,只能使用在class上面?

@zkboys
Copy link
Contributor

zkboys commented Sep 12, 2019

请问,异步加载菜单的方法里面该如何引入ajax请求后端菜单?
使用文档中推荐的三种方式,都会报错,只能使用在class上面?

参考代码如下:

import {sxAjax} from '@/commons/ajax';

/*
* 菜单数据 返回Promise各式,支持前端硬编码、异步获取菜单数据
* */
export default function getMenus() {
    return sxAjax.get('/menus')
        .then(res => {
            const menus = [];

            if (res && res.length) {
                res.forEach(item => {
                    let {id: key, parentId: parentKey, name: text, order, url: path} = item;
                    const isParent = !!res.find(item => item.parentId === key);

                    order = window.parseInt(order) || 0;

                    menus.push({
                        key: `${key}`,
                        parentKey: `${parentKey}`,
                        text,
                        path,
                        order,
                        icon: isParent ? 'folder' : 'file-text',
                    });
                });
            }

            return menus;
        });
}

@zkboys zkboys closed this as completed Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants