dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

求在组件中switch的用法 #250

Closed junmaqiang closed 7 years ago

junmaqiang commented 7 years ago

我尝试过用三元运算法没有问题, 但是用switch就有问题, 请教朋友们在组件里面如何使用 switch 求写法,谢谢!

junmaqiang commented 7 years ago

我的写法是这酱紫的

<Menu mode="horizontal" selectedKeys={[MenuKey]}>
   {
      switch (MenuKey) {
       case 'config':
           return '<Menu.Item key="config"><Link to="/config">配置</Link></Menu.Item>'
           break;
       default:
           return '<Menu.Item key="order"><Link to="/order">订单</Link></Menu.Item>'
    }
  }
</Menu>
lincenying commented 7 years ago
const a = 1
    let b
    switch (a) {
        case 1:
            b = <div>1</div>
            break
        case 2:
            b = <div>2</div>
            break
        default:
            b = <div>3</div>
    }

//////////

{ b }
junmaqiang commented 7 years ago

搞定了,谢谢楼上的朋友,非常感谢!

junmaqiang commented 7 years ago

我又出问题啦 就是一个Menu.Item 没问题,两个Menu.Item 连起来就出问题,求助!

   case 'spider':
        SelectMenu = <Menu.Item key="gua"><Link to="/gua">配置</Link></Menu.Item>
        break
    case 'tun':
        SelectMenu = <Menu.Item key="tun"><Link to="/tunmo">吞没</Link></Menu.Item><Menu.Item key="gua"><Link to="/gua">算法</Link></Menu.Item>
        break
    default:
        SelectMenu = <Menu.Item key="other"><Link to="/other">其他算法</Link></Menu.Item>
lincenying commented 7 years ago

只能有一个顶级标签. 相邻jsx元素必须被包裹在一个封闭的标签里

junmaqiang commented 7 years ago

谢谢,按照您说的我增加了 <div> 包裹起来就OK了。非常感谢