Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
马贞晓
/
templateReact
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a8076eb1
authored
Nov 13, 2019
by
马贞晓
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
完成修改
1 parent
b6656c34
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
README.md
src/view/index/index.js
README.md
View file @
a8076eb
### 运行
```
java
yarn
start
npm
run
start
//开发
yarn
build
npm
run
build
//打包
```
### 依赖
*
axios
*
redux
*
react-router-dom
#### axios 使用
> service中重新定义GET POST
```
javascript
import
$http
from
"../../service"
;
//页面引入统一service
$http
.
GET
(
"/test"
)
.
then
(
d
=>
{
debugger
})
.
catch
(
e
=>
{
debugger
})
```
#### redux 使用
>页面引入redux的connct,采用装饰器模式过滤所需state
```
javascript
import
{
connect
}
from
"react-redux"
;
@
connect
((
state
)
=>
{
// debugger
let
{
layout
,
login
}
=
state
return
{
layout
,
login
};
})
class
Demo
extends
Component
{}
```
> 页面修改redux,type类型为枚举类型,防止胡乱定义
```
javascript
import
EVENT
from
"../../store/EVENT"
this
.
props
.
dispatch
({
type
:
EVENT
.
LOGIN
,
payload
:{
name
:
"hehehe"
}
})
```
#### react-router-dom
> 页面中引入路由跳转,使用Link组件跳转和动态跳转
```
javascript
import
{
Link
}
from
"react-router-dom"
;
//组件跳转
this
.
props
.
history
.
push
(
"/index2"
)
//动态跳转
```
\ No newline at end of file
src/view/index/index.js
View file @
a8076eb
...
...
@@ -36,7 +36,9 @@ import $http from "../../service";
* @name 同步修改
*/
EventClick
(
item
){
this
.
props
.
history
.
push
(
"/index2"
)
console
.
log
(
this
.
props
);
return
this
.
props
.
dispatch
({
type
:
EVENT
.
LAYOUT
,
payload
:{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment