Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf9a040

Browse files
committedJun 16, 2020
add prettier and format
1 parent 0da0e52 commit cf9a040

21 files changed

+262
-226
lines changed
 

‎.eslintrc.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ module.exports = {
33
env: {
44
node: true
55
},
6-
extends: ["plugin:vue/essential", "@vue/prettier"],
6+
extends: ['plugin:vue/essential', '@vue/prettier'],
77
rules: {
8-
"no-console": process.env.NODE_ENV === "production" ? "error" : "off",
9-
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
8+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
9+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
1010
},
1111
parserOptions: {
12-
parser: "babel-eslint"
12+
parser: 'babel-eslint'
1313
}
14-
};
14+
}

‎.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ yarn-error.log*
1313

1414
# Editor directories and files
1515
.idea
16-
.vscode
1716
*.suo
1817
*.ntvs*
1918
*.njsproj

‎.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"printWidth": 80,
5+
"tabWidth": 2,
6+
"useTabs": false,
7+
"trailingComma": "none"
8+
}

‎.vscode/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// 编辑器保存自动格式化
3+
"editor.formatOnSave": true,
4+
// 锁紧字符
5+
"editor.tabSize": 2,
6+
// 自动在vscode顶部显示文件路径
7+
"window.title": "${dirty}${activeEditorMedium}${separator}${rootName}",
8+
// 搜索排除
9+
"search.exclude": {
10+
"**/node_modules": true,
11+
"**/bower_components": true,
12+
"**/dist": true
13+
},
14+
// 控制是否在搜索中跟踪符号链接,会导致cpu内存占有率过高
15+
"search.followSymlinks": false,
16+
// 自动fetch远程分支
17+
"git.autofetch": true,
18+
// eslint开启
19+
"eslint.enable": true,
20+
// eslint自动保存格式话
21+
"editor.codeActionsOnSave": {
22+
"source.fixAll.eslint": true
23+
},
24+
// 保存超时时长
25+
"editor.codeActionsOnSaveTimeout": 2500,
26+
// 依赖prettier配置文件来格式化
27+
"prettier.requireConfig": true
28+
}

‎babel.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: ["@vue/app"]
3-
};
2+
presets: ['@vue/app']
3+
}

‎postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module.exports = {
22
plugins: {
33
autoprefixer: {}
44
}
5-
};
5+
}

‎src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<style lang="scss">
1111
#app {
12-
font-family: "Avenir", Helvetica, Arial, sans-serif;
12+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
1313
-webkit-font-smoothing: antialiased;
1414
-moz-osx-font-smoothing: grayscale;
1515
text-align: center;

‎src/api/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
import axios from "axios";
2-
const TARGET_SERVER = process.env.VUE_ENV === "server";
1+
import axios from 'axios'
2+
const TARGET_SERVER = process.env.VUE_ENV === 'server'
33
// FOR PROXY TEST: const cnodeBaseUrl = TARGET_SERVER ? process.env.config.CNODE_HOST : "/feapi";
4-
const cnodeBaseUrl = process.env.config.CNODE_HOST;
4+
const cnodeBaseUrl = process.env.config.CNODE_HOST
55
export function fetchTopics({ cookies }) {
6-
return axios.get(cnodeBaseUrl + "/api/v1/topics", {
6+
return axios.get(cnodeBaseUrl + '/api/v1/topics', {
77
headers: getCommonHeader({ cookies })
8-
});
8+
})
99
}
1010

1111
export function fetchTopicDetail({ id, cookies }) {
1212
return axios.get(cnodeBaseUrl + `/api/v1/topic/${id}`, {
1313
headers: getCommonHeader({ cookies })
14-
});
14+
})
1515
}
1616

1717
function getCommonHeader({ cookies }) {
1818
if (TARGET_SERVER && cookies) {
19-
return { cookie: getCookieString(cookies) };
19+
return { cookie: getCookieString(cookies) }
2020
} else {
21-
return null;
21+
return null
2222
}
2323
}
2424

2525
function getCookieString(cookies) {
26-
let cookieStr = "";
26+
let cookieStr = ''
2727
for (var variable in cookies) {
28+
// eslint-disable-next-line no-prototype-builtins
2829
if (cookies.hasOwnProperty(variable)) {
29-
cookieStr += `${variable}=${encodeURIComponent(cookies[variable])}; `;
30+
cookieStr += `${variable}=${encodeURIComponent(cookies[variable])}; `
3031
}
3132
}
32-
return cookieStr;
33+
return cookieStr
3334
}

‎src/components/TopicItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
<script>
99
export default {
10-
name: "TopicItem",
10+
name: 'TopicItem',
1111
serverCacheKey: props => props.topicInfo.id, // for ssr cache item component
1212
props: {
1313
topicInfo: Object
1414
}
15-
};
15+
}
1616
</script>
1717

1818
<!-- Add "scoped" attribute to limit CSS to this component only -->

‎src/entry-client.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createApp } from "./main";
2-
const { app, router, store } = createApp();
1+
import { createApp } from './main'
2+
const { app, router, store } = createApp()
33

44
// prime the store with server-initialized state.
55
// the state is determined during SSR and inlined in the page markup.
66
if (window.__INITIAL_STATE__) {
7-
store.replaceState(window.__INITIAL_STATE__);
7+
store.replaceState(window.__INITIAL_STATE__)
88
}
99
router.onReady(() => {
10-
app.$mount("#app");
11-
});
10+
app.$mount('#app')
11+
})

‎src/entry-server.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createApp } from "./main";
1+
import { createApp } from './main'
22

33
// This exported function will be called by `bundleRenderer`.
44
// This is where we perform data-prefetching to determine the
@@ -7,10 +7,10 @@ import { createApp } from "./main";
77
// return a Promise that resolves to the app instance.
88
export default context => {
99
return new Promise((resolve, reject) => {
10-
const beginTime = Date.now();
11-
const { app, router, store } = createApp();
10+
const beginTime = Date.now()
11+
const { app, router, store } = createApp()
1212
// set router's location
13-
router.push(context.url);
13+
router.push(context.url)
1414
router.onReady(() => {
1515
// This `rendered` hook is called when the app has finished rendering
1616
context.rendered = () => {
@@ -19,11 +19,11 @@ export default context => {
1919
// When we attach the state to the context, and the `template` option
2020
// is used for the renderer, the state will automatically be
2121
// serialized and injected into the HTML as `window.__INITIAL_STATE__`.
22-
context.state = store.state;
22+
context.state = store.state
2323
/* eslint-disable-next-line */
2424
console.log(`[DATE] data pre-fetch: ${Date.now() - beginTime}ms url=${context.url}`);
25-
};
26-
resolve(app);
27-
}, reject);
28-
});
29-
};
25+
}
26+
resolve(app)
27+
}, reject)
28+
})
29+
}

‎src/main.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
import Vue from "vue";
2-
import App from "./App.vue";
3-
import { createRouter } from "./router";
4-
import { createStore } from "./store";
5-
import { sync } from "vuex-router-sync";
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
import { createRouter } from './router'
4+
import { createStore } from './store'
5+
import { sync } from 'vuex-router-sync'
66

77
//关闭生产模式下给出的提示
8-
Vue.config.productionTip = true;
8+
Vue.config.productionTip = true
99

1010
// for using vant components
11-
import Vant from "vant";
12-
import "vant/lib/index.css";
13-
Vue.use(Vant);
11+
import Vant from 'vant'
12+
import 'vant/lib/index.css'
13+
Vue.use(Vant)
1414
// global loading
1515
Vue.prototype.$loading = isLoading => {
1616
if (isLoading) {
1717
Vue.prototype.$toast.loading({
1818
mask: true,
19-
message: "加载中...",
19+
message: '加载中...',
2020
overlayStyle: {
21-
backgroundColor: "rgba(0, 0, 0, 0.1)"
21+
backgroundColor: 'rgba(0, 0, 0, 0.1)'
2222
},
2323
duration: 0
24-
});
24+
})
2525
} else {
26-
Vue.prototype.$toast.clear();
26+
Vue.prototype.$toast.clear()
2727
}
28-
};
28+
}
2929

3030
export function createApp() {
31-
const router = createRouter();
32-
const store = createStore();
31+
const router = createRouter()
32+
const store = createStore()
3333
// sync the router with the vuex store.
3434
// this registers `store.state.route`
35-
sync(store, router);
35+
sync(store, router)
3636
const app = new Vue({
3737
router,
3838
store,
3939
render: h => h(App)
40-
});
41-
return { app, router, store };
40+
})
41+
return { app, router, store }
4242
}
4343

4444
// promise.finally Polyfill
4545
if (!Promise.prototype.finally) {
4646
Promise.prototype.finally = function(callback) {
47-
let P = this.constructor;
47+
let P = this.constructor
4848
return this.then(
4949
value => P.resolve(callback()).then(() => value),
5050
reason =>
5151
P.resolve(callback()).then(() => {
52-
throw reason;
52+
throw reason
5353
})
54-
);
55-
};
54+
)
55+
}
5656
}

‎src/router/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import Vue from "vue";
2-
import Router from "vue-router";
3-
import Home from "../views/Home.vue";
1+
import Vue from 'vue'
2+
import Router from 'vue-router'
3+
import Home from '../views/Home.vue'
44

5-
Vue.use(Router);
5+
Vue.use(Router)
66

77
export function createRouter() {
88
return new Router({
9-
mode: "history",
9+
mode: 'history',
1010
routes: [
1111
{
12-
path: "/",
13-
name: "home",
12+
path: '/',
13+
name: 'home',
1414
component: Home
1515
},
1616
{
17-
path: "/detail/:id",
18-
name: "detail",
17+
path: '/detail/:id',
18+
name: 'detail',
1919
// route level code-splitting
2020
// this generates a separate chunk (about.[hash].js) for this route
2121
// which is lazy-loaded when the route is visited.
2222
component: () =>
23-
import(/* webpackChunkName: "detail" */ "../views/Detail.vue")
23+
import(/* webpackChunkName: "detail" */ '../views/Detail.vue')
2424
}
2525
]
26-
});
26+
})
2727
}

‎src/store/actions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { fetchTopics, fetchTopicDetail } from "../api";
1+
import { fetchTopics, fetchTopicDetail } from '../api'
22

33
export default {
44
FETCH_TOPICS_LIST: ({ commit, state }, { cookies }) => {
55
return state.topicsList
66
? Promise.resolve()
77
: fetchTopics({ cookies }).then(res =>
8-
commit("SET_TOPICS_LIST", { list: res.data.data })
9-
);
8+
commit('SET_TOPICS_LIST', { list: res.data.data })
9+
)
1010
},
1111
FETCH_TOPIC_DETAIL: ({ commit }, { id, cookies }) => {
1212
return fetchTopicDetail({ id, cookies }).then(res =>
13-
commit("SET_TOPIC_DETAIL", { detail: res.data.data })
14-
);
13+
commit('SET_TOPIC_DETAIL', { detail: res.data.data })
14+
)
1515
}
16-
};
16+
}

‎src/store/getters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export default {
22
// aboutInfo (state) {
33
// return state.pageAbout
44
// }
5-
};
5+
}

‎src/store/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Vue from "vue";
2-
import Vuex from "vuex";
3-
import actions from "./actions";
4-
import mutations from "./mutations";
5-
import getters from "./getters";
1+
import Vue from 'vue'
2+
import Vuex from 'vuex'
3+
import actions from './actions'
4+
import mutations from './mutations'
5+
import getters from './getters'
66

7-
Vue.use(Vuex);
7+
Vue.use(Vuex)
88

99
export function createStore() {
1010
return new Vuex.Store({
@@ -16,5 +16,5 @@ export function createStore() {
1616
mutations,
1717
actions,
1818
getters
19-
});
19+
})
2020
}

‎src/store/mutations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default {
22
SET_TOPICS_LIST: (state, { list }) => {
3-
state.topicsList = list;
3+
state.topicsList = list
44
},
55
SET_TOPIC_DETAIL: (state, { detail }) => {
6-
state.topicDetail = detail;
6+
state.topicDetail = detail
77
}
8-
};
8+
}

0 commit comments

Comments
 (0)
Please sign in to comment.