typescript react webpack配置
配置webpack
需安装ts-loader和source-map-loader
ts-loader用于解析ts,source-map-loader用于映射生成的js
新建webpack.config.js
123456789101112131415161718///webpack.config.jsvar path = require('path')module.exports = { entry: './src/index.tsx', output: { path: path.join(__dirname, 'build'), filename: 'bundle.js', }, module: { rules: [ { test: /\.tsx?$/, loader: "ts-loader" }, { ...
Router组件history参数[v3/v4/v5]的区别
v3Router需传入history参数,可选值为'react-router'中的hashHistory、browserHistory
12import {Router, history} from 'react-router'<Router hisotry={hashHistory}/>
v4history参数放入'react-router-dom'中
'react-router-dom'基于'react-router',包含浏览器相关特性,如history、Link等
123import {Router} from 'react-router'import {hashHistory} from 'react-router-dom'<Router history={history}/>
v5hashHistory和browserHist ...
Ubuntu安装与卸载conda
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
安装
下载对应版本的sh文件 https://docs.conda.io/en/latest/miniconda.html#linux-installers
安装
1sh filename.sh
重启终端,环境生效
卸载
删除安装文件
1rm -rf /path/to/conda
删除环境变量
1vim ~/.bashrc
删除其中的conda配置
删除配置和缓存文件
1rm -rf ~/.condarc ~/.conda ~/.continuum
env导入导出
导出
打开cmd或bash(powershell不支持activate)
激活需导出的环境
1activate [envname]
导出环境至yml文件
1conda env export>filename.yml
泛型
需要引入TypeVar和Generic
在泛型类前定义范型变量
泛型类继承自Generic[范型变量]
函数使用方法和其他语言相同
e.g.12345678from typing import TypeVar, GenericT1 = TypeVar('T1')T2 = TypeVar('T2')class GenericTest(Generic[T1, T2]): def test_fun(self, info: T1) -> T2: return T2(T1);
连接MySQL
导包python2使用mysqldb包
python3使用pymysql包
数据库连接池
DBUtils(推荐) 可以连接多种数据库模块
pymysqldbpool 只能使用pymysql模块
PS: 这两个包我在conda没找到,pip可以安装
连接池DBUtils有两种连接池
PooledDB(多连接共用一个线程)
PersistentDB(每个连接单独一个线程)
以PooledDB为例
导入1from DBUtils.PooledDB import PooledDB
连接数据库12345678910111213# 常用参数PooledDB( host='ip' port='3306' # 端口, 默认3306 user='用户名' password='密码' db='默认数据库' charset='字符集' creator=pymysql # 数据库模块 mincached=0 # 初始化时的连接数, ...
Added non-passive event listener to a scroll-blocking 'mousewheel' event
原因Chrome新增被动(passive)监听器以优化页面滚动性能
方法
安装被动监听器
1npm install --save default-passive-events
在警告的页面引入该包,浏览器会自动进行决策
1import 'default-passive-events'
从Enum的value获得key
问题已知
123456enum ChartType { PIE = '饼图', BAR = '柱状图', MAP = '地图'}var t='饼图';
得到对应的ChartType类型
方法遍历enum类型
123456for (let i in ChartType) { let c = ChartType[i as keyof typeof ChartType] if (c === activeKey) { return c; }}
string转enum
问题已知
123456enum ChartType { PIE = '饼图', BAR = '柱状图', MAP = '地图'}var c='PIE';
如何得到对应的ChartType类型
方法1EnumType[keystring]
如果类型错误
1EnumType[keystring as keyof typeof ChartType]
即
e.g.1t: ChartType = ChartType[c as keyof typeof ChartType]
git删除历史文件
删除单个文件1git filter-branch --force --index-filter "git rm --cached --ignore-unmatch path/to/your/remove/file" --prune-empty --tag-name-filter cat -- --all
路径前不能有”/“
删除文件夹在git rm后添加-r参数即可
1git filter-branch --force --index-filter "git rm -r --cached --ignore-unmatch path/to/your/remove/directory" --prune-empty --tag-name-filter cat -- --all
路径前不能有”/“
错误1bad revision 'rm'
应使用双引号