class类组件:
// 定义组件
class MyComponent<P> extends React.Component<P> {
internalProp: P;
constructor(props: P) {
super(props);
this.internalProp = props;
}
render() {
return (
<span>hello world</span>
);
}
}
// 使用组件
type IProps = { n...阅读全文>>
类组件中
React.createRef()
优点:通俗易懂,用ref指向。
缺点:使用了HOC的子组件不可用,无法指向真是子组件
比如一些常用的写法,mobx的@observer包裹的子组件就不适用此方法。
import React, { Component } from 'react';
class Sub extends Component {
callback() {
console.log('执行回调');
}
render() {
return <div>子组件</div>;
...阅读全文>>
import npminstall from 'npminstall';
npminstall({
root: this.targetPath,
storeDir: this.storePath,
registry: getNpmRegistry(),
pkgs: [
{
name: this.packageName,
version: this.packageVersion
}
]
});阅读全文>>
一、前言
最近准备开发前端的一个模块化的库,业务级别,要求可以任意插拔随意组合。大型工程,需要多人维护。
以前的项目都是业务级,单个包项目。简单,便于管理。但是,当一个大的项目库代码量剧增之后,管理起来就是一件比较麻烦的事情,为了方便代码的共享,就需要将代码库拆分成独立的包。
调研了一下lerna库,适合我们的场景,babel即用这个工具进行管理。
二、lerna基础
初始化:
$ npm i -g lerna
$ mkdir lerna-repo && cd $_ $ lerna init
...阅读全文>>
const cac = require('cac');
const cli = cac.cac('lininn-theme');
cli.command('', '生成样式文件')
.option('-p, --platform <platform>', '配置平台')
.option('--prefix <prefix>', '配置前缀')
.option('--font <font>', '配置字体大小:normal|large|small,默认 normal')
.option...阅读全文>>
阅读全文>>
Step 1️:创建一个 Store Model
// ./src/stores/todo.ts
import { action, observable, computed } from 'mobx';
export interface ITodo {
id: number;
name: string;
desc: string;
done?: boolean;
}
let id = 0;
export class TodoStore {
@observable todos: ITodo[] = [];
// 利用计算属性计算完成个未完成个数
@compu...阅读全文>>
settings.json:
"eslint.options": {
"overrideConfig": {
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"rules": {
"no-debugger": "off"
}
}
},阅读全文>>
export default defineConfig({
cssLoader: {
modules: {
auto: true,
},
},
})阅读全文>>
window.location.replace
1
window.location.replace('要转向的页面') //不会有历史记录
1 2 3 4
let backLen = history.length history.forward() history.go(-backLen) // Return at the beginning window.location.replace('/#/home')
...阅读全文>>