antd配置config-overrides.js文件的操作
下載antd 包
npm install antd
下載依賴包(定義組件按需求打包)
npm install react-app-rewired customize-cra babel-plugin-import
自定義less-loader,改變antd默認(rèn)樣式
npm install less less-loader
根目錄定義加載按需打包的js配置模塊: config-overrides.js
const {override,fixBabelImports,addLessLoader} =require('customize-cra'); module.exports = override( // 針對(duì)antd 實(shí)現(xiàn)按需打包:根據(jù)import來打包 (使用babel-plugin-import) fixBabelImports('import',{ libraryName:'antd', libraryDirectory:'es', style:true,//自動(dòng)打包相關(guān)的樣式 默認(rèn)為 style:'css' }), // 使用less-loader對(duì)源碼重的less的變量進(jìn)行重新制定,設(shè)置antd自定義主題 addLessLoader({ javascriptEnabled: true, modifyVars:{'@primary-color':'#1DA57A'}, }) );
修改packge.json 的配置文件
"scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react--app-rewired test", "eject": "react-scripts eject" },
在app.js引入需要的antd模塊:
import React ,{Component} from 'react'; import { Button , message} from 'antd'; /* 應(yīng)用的根組件 */ export default class App extends Component{ handleClick = ()=>{ message.success('成功啦') } render(){ return ( <Button type="primary" onClick={this.handleClick}>測(cè)試antd</Button> ) } }
補(bǔ)充知識(shí):Vue 監(jiān)聽鼠標(biāo)左鍵 鼠標(biāo)右鍵以及鼠標(biāo)中鍵修飾符click.left&contextmenu&click.middle
我就廢話不多說了,大家還是直接看代碼吧~
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <script src="vue.js"></script> <title id="title">{{title}}</title> </head> <body> <div id="ask"><!--vue不能控制body和html的標(biāo)簽--> <!--鼠標(biāo)左鍵--> <div :style="left_style" @click.left="mouseclick('左')"></div> <!--鼠標(biāo)中鍵--> <div :style="middle_style" @click.middle="mouseclick('中')"></div> <!--鼠標(biāo)右鍵--> <!--加prevent為了屏蔽瀏覽器自帶右鍵--> <div :style="right_style" @contextmenu.prevent="mouseclick('右')"></div> </div> <script> var vue = function (options){new Vue(options)}; vue({ el:'#title', data:{ title:'Vue 監(jiān)聽鼠標(biāo)左鍵 鼠標(biāo)右鍵以及鼠標(biāo)中鍵修飾符click.left&contextmenu&click.middle' } }); var app = vue({ el:'#ask', data:{ left_style:{border:'solid 2px red',height:'200px'}, right_style:{border:'solid 2px blue',height:'200px'}, middle_style:{border:'solid 2px yellow',height:'200px'}, }, methods:{ mouseclick(where){ alert('點(diǎn)擊鼠標(biāo)'+where+'鍵觸發(fā)'); }, } }); </script> </body> </html>
以上這篇antd配置config-overrides.js文件的操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用element組件table表格實(shí)現(xiàn)某條件下復(fù)選框無法勾選
這篇文章主要介紹了使用element組件table表格實(shí)現(xiàn)某條件下復(fù)選框無法勾選問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03element中el-table中的el-input校驗(yàn)的實(shí)現(xiàn)
本文主要介紹了element中el-table中的el-input校驗(yàn)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08vue.js將時(shí)間戳轉(zhuǎn)化為日期格式的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue.js將時(shí)間戳轉(zhuǎn)化為日期格式的實(shí)現(xiàn)代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-06-06vue通過子組件修改父組件prop的多種實(shí)現(xiàn)方式
這篇文章主要介紹了vue通過子組件修改父組件prop的幾種實(shí)現(xiàn)方式,比較常用的方式是通過Prop單向傳遞的規(guī)則,需要的朋友可以參考下2021-09-09