在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 有沒有總辦法修改 antd 組件的默認(rèn)參數(shù)

有沒有總辦法修改 antd 組件的默認(rèn)參數(shù)

比如 Button 的默認(rèn)屬性 ghost 的值是 false,我想在我的項(xiàng)目中所有的 Button 的默認(rèn) ghost 都為 true

我現(xiàn)在的代碼,所有的 Button 都要寫上 ghost 屬性

<Button ghost={true}></Button>

我想要實(shí)現(xiàn),經(jīng)過我簡單的設(shè)置后,我在項(xiàng)目中使用 button 不需要使用 ghost 參數(shù),也就是把原來的 Button 組件的默認(rèn)參數(shù)篡改為 true

只需要:

<Button></Button>

不想要時(shí)

<Button ghost={false}></Button>
回答
編輯回答
溫衫

myButton.js

import {Button} from 'antd'
export default props => {
  if(!(props && props.hasOwnProperty('ghost'))) {
    props = {...props, ghost: true}; 
  }
  return <Button {...props}>{props.children}</Button>
}

using

import Button from './myButton.js';
<Button>確定</Button>
2017年12月30日 23:32
編輯回答
單眼皮

那你自己再用高階組件封裝一個(gè)button不就完了嗎?改他的代碼肯定是不科學(xué)的,偽代碼如下,你可以改成組件式的寫法

import {Button} from 'antd'
function myButton(props = {}) {
    if(ghost in props) {
        return <Button ghost={props.ghost}>xxx</Button>
    }
    return <Button ghost={true}>xxx</Button>
}
2018年5月20日 22:16