Skip to content

Commit d0a0c5d

Browse files
committed
first add
1 parent edfd203 commit d0a0c5d

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/**/*-test.js
2+
src/public

.eslintrc.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
** 项目工作台-代码检测规则
3+
** create by whr
4+
** time: 2017.11.8
5+
*/
6+
module.exports = {
7+
env: {
8+
browser: true,
9+
node: true,
10+
"es6": true
11+
},
12+
"rules": {
13+
"radix": 0,
14+
"no-plusplus": 0,
15+
"import/first": 0,
16+
"class-methods-use-this": 0,
17+
"array-callback-return": 0,
18+
"no-mixed-operators": 0,
19+
"no-irregular-whitespace": 0,
20+
"react/no-unescaped-entities": 0,
21+
"no-prototype-builtins": 0,
22+
"template-curly-spacing": 0,
23+
"arrow-parens": 0,
24+
"space-infix-ops": 0,
25+
"jsx-a11y/alt-text": 0,
26+
"no-shadow": 0,
27+
"consistent-return": 0,
28+
"no-case-declarations": 0,
29+
"wrap-iife": 0,
30+
"camelcase": 0,
31+
"quotes": 0,
32+
"jsx-a11y/no-noninteractive-element-interactions": 0,
33+
"semi": [
34+
0,
35+
"never"
36+
],
37+
"no-console": 1,
38+
"no-extra-semi": 1,
39+
"no-func-assign": 1,
40+
"no-unreachable": 1,
41+
"constructor-super": 2,
42+
"no-const-assign": 2,
43+
"no-var": 1,
44+
"no-eval": 1,
45+
"no-unused-vars": 1,
46+
"no-debugger": 1,
47+
"one-var": 0,
48+
"comma-dangle": 0,
49+
"max-len": 0,
50+
"react/jsx-first-prop-new-line": 0,
51+
"react/jsx-filename-extension": 0,
52+
"space-before-function-paren": 0,
53+
"no-unused-expressions": [
54+
0,
55+
{
56+
"allowShortCircuit": true,
57+
"allowTernary": true
58+
}
59+
],
60+
"arrow-body-style": [
61+
0,
62+
"never"
63+
],
64+
"func-names": 0,
65+
"prefer-const": 0,
66+
"no-extend-native": 0,
67+
"no-param-reassign": 0,
68+
"no-restricted-syntax": 0,
69+
"no-continue": 0,
70+
"react/jsx-no-bind": 0,
71+
"no-underscore-dangle": 0,
72+
"global-require": 0,
73+
"import/no-unresolved": 0,
74+
"import/extensions": 0,
75+
"jsx-a11y/href-no-hash": 0,
76+
"react/no-array-index-key": 0,
77+
"react/require-default-props": 0,
78+
"react/forbid-prop-types": 0,
79+
"react/no-string-refs": 0,
80+
"react/no-find-dom-node": 0,
81+
"react/prefer-stateless-function": 0,
82+
"import/no-extraneous-dependencies": 0,
83+
"import/prefer-default-export": 0,
84+
"react/no-danger": 0,
85+
"jsx-a11y/no-static-element-interactions": 0,
86+
"space-before-blocks": 0,
87+
"indent": 0,
88+
"no-tabs": 0,
89+
"no-mixed-spaces-and-tabs": 0,
90+
"quote-props": 0,
91+
"react/jsx-indent": 0,
92+
"react/sort-comp": 0,
93+
"react/prop-types": 0,
94+
"no-trailing-spaces": 0,
95+
"object-shorthand": 0,
96+
"react/jsx-curly-spacing": 0,
97+
"import/newline-after-import": 0,
98+
"object-curly-spacing": 0,
99+
"keyword-spacing": 0,
100+
"no-else-return": 0,
101+
"prefer-template": 0,
102+
"no-return-assign": 0,
103+
"vars-on-top": 0,
104+
"spaced-comment": 0,
105+
"react/self-closing-comp": 0,
106+
"no-lonely-if": 0,
107+
'linebreak-style': 'off',
108+
},
109+
"parser": "babel-eslint", //解析器
110+
"parserOptions": {
111+
"sourceType": "module",
112+
"ecmaVersion": 8,
113+
"ecmaFeatures": {
114+
"jsx": true,
115+
"experimentalObjectRestSpread": true
116+
}
117+
},
118+
"settings": {
119+
"import/resolver": "node",
120+
}
121+
}

entry.ejs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>axios-demo</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
</body>
11+
</html>

index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import axios from "axios";
2+
3+
console.log('defaults:', axios.defaults);
4+
5+
// 设置通用头部
6+
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
7+
8+
// 跨域携带cookie
9+
axios.defaults.headers.common['withCredentials'] = true;
10+
11+
// 拦截请求
12+
axios.interceptors.request.use(config => {
13+
config.headers['Authorization'] = 'whr2'
14+
return config
15+
}, error => {
16+
console.log(error);
17+
})
18+
19+
// 拦截响应
20+
axios.interceptors.response.use(data => {
21+
return data
22+
}, error => {
23+
console.log(error);
24+
})
25+
26+
console.log('interceptors:', axios.interceptors);
27+
28+
axios.get('http://jsonplaceholder.typicode.com/users', {
29+
params: {
30+
b: 2
31+
},
32+
headers: {
33+
'Authorization': 'whr',
34+
}
35+
})
36+
.then(data => {
37+
// console.log(data);
38+
})
39+
.catch(err => {
40+
// console.log(err);
41+
})

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "axios-demo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "webpack-dev-server --mode=development",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"axios": "^0.18.0"
15+
},
16+
"devDependencies": {
17+
"babel": "^6.23.0",
18+
"babel-core": "^6.26.3",
19+
"babel-eslint": "^8.2.3",
20+
"babel-loader": "^7.0.0",
21+
"babel-plugin-transform-runtime": "^6.23.0",
22+
"babel-preset-env": "^1.7.0",
23+
"babel-preset-stage-3": "^6.24.1",
24+
"babel-runtime": "^6.26.0",
25+
"eslint": "^4.19.1",
26+
"html-webpack-plugin": "^3.2.0",
27+
"webpack": "^4.8.3",
28+
"webpack-cli": "^2.1.3",
29+
"webpack-dev-server": "^3.1.4"
30+
}
31+
}

webpack.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
const HtmlWebpackPlugin = require('html-webpack-plugin')
4+
5+
module.exports = {
6+
entry: './index.js',
7+
mode: 'development',
8+
module: {
9+
rules: [
10+
{
11+
test: /\.js$/i,
12+
exclude: /(node_modules|bower_components)/,
13+
use: {
14+
loader: 'babel-loader',
15+
options: {
16+
presets: ['env', 'stage-3'],
17+
plugins: ['transform-runtime'],
18+
}
19+
},
20+
}
21+
]
22+
},
23+
devtool: 'eval-source-map',
24+
plugins: [
25+
new HtmlWebpackPlugin({
26+
template: `${__dirname}/entry.ejs`,
27+
filename: 'index.html',
28+
}),
29+
],
30+
devServer: {
31+
contentBase: path.join(__dirname, "dist"),
32+
compress: true,
33+
port: 9000
34+
},
35+
}

0 commit comments

Comments
 (0)