You need to sign in or sign up before continuing.
Commit d8c6b610 authored by huanglu's avatar huanglu

init

parents
> 1%
last 2 versions
not dead
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
VUE_APP_API_HOST = ''
VUE_APP_API_HOST = ''
\ No newline at end of file
VUE_APP_API_HOST = ''
\ No newline at end of file
module.exports = {
root: true,
env: {
node: true,
},
extends: [
'plugin:vue/essential',
'@vue/airbnb',
],
parserOptions: {
parser: 'babel-eslint',
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'comma-dangle': 0,
'comma-spacing': 0,// 逗号前后的空格
'comma-style': [2, 'last'],// 逗号风格,换行时在行首还是行尾
quotes: [1, 'single'],
eqeqeq: 2,
'no-var': 1,
'key-spacing': [2, { beforeColon: false, afterColon: true }],// 对象字面量中冒号的前后空格
semi: 0,
'semi-spacing': [0, { before: false, after: true }], // 分号前后空格,
'use-isnan': 2, // 禁止比较时使用NaN,只能用isNaN()
'prefer-promise-reject-errors': 0,
'no-param-reassign': 0,
'no-unused-vars': 1,
'no-shadow': 0,
'import/extensions': 0,
'import/prefer-default-export': 1,
'eol-last': 0
},
};
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"types": ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"],
"scope": {
"required": false,
"allowed": ["*"],
"validate": false,
"multiple": false
},
"warnOnFail": false,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "subject does not match subject pattern!",
"helpMessage": "",
"autoFix": false
}
\ No newline at end of file
# geek-vue-template
## 使用方法:
- 通过 git 直接 克隆到本地,然后删除 .git 文件夹目录, 修改 package.json的name等数据(不建议)
- 通过 fastgeek create 命令创建项目
- 目录结构
- 在 src/views 目录下创建路由文件
- 路由建议通过 名称/ index.vue 的方式创建
- 在 src/store/modules 文件夹下创建 全局状态数据,且创建后,可以自动注入到全局状态中, 状态的命名即文件名,所有文件名建议不要使用 [store].js 的格式
- 在 src/global 下的文件是全局样式文件
- common.less 放在一些全局的函数、mixins、公共的样式等, 如 border, rpx() 等
- variable.less 放一些全局的样式变量,如颜色,大小等
- 在 src/constant 目录下,放置 一些全局变量, 并统一使用 该 目录下的 index.js 导出
- 在 src/component 放置全局组件, 如果非全局组件,建议放在对应的路由目录的 component 目录下,并统一在 component / index.js 统一导出
- 在 src/ router 文件中,配置路由,建议使用懒加载
- 在根目录中的 public 目录下,可以保存不需要 webpack 编译的文件
- 根目录下 config 目录下进行项目配置(一般不需要再配置)
- mock目录下可以编写mock数据
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
],
};
const path = require('path');
const resolve = (dir) => {
return path.join(__dirname, '..', dir)
}
module.exports = {
proxy: {
'/api': {
target: 'http://localhost:3000',
pathRewrite: { '^/api': '' },
},
},
publicPath: '/',
alias: { // 配置这个,注意配置 jsconfig.json 文件,方便 vscode 能够跳进
"@": resolve('src')
}
}
const path = require('path')
const fs = require('fs')
const multiPages = () => {
const pagesPath = path.join(__dirname, '../src/pages')
const pages = {}
console.log(pagesPath)
if(fs.existsSync(pagesPath)) {
const files = fs.readdirSync(pagesPath)
console.log(files)
files.forEach(item => {
const fileName = item.split('.')[0];
pages[fileName] = `src/pages/${fileName}/index.js`
})
} else {
return null
}
return pages
}
module.exports = {
multiPages
}
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
}
}
}
\ No newline at end of file
module.exports = {
'/userinfo': (req, res) => {
setTimeout(() => {
res.json({
code: 1,
message: '',
data: 'this is hello api',
});
}, 1000);
},
'/hello': {
code: 1,
message: '',
data: 'this is hello api',
},
'POST /login': {
code: 1,
message: '',
data: 'this is hello api',
},
};
{
"name": "jst-jy-v2",
"version": "0.1.0",
"private": true,
"fastgeek": "vue",
"scripts": {
"serve:dev": "vue-cli-service serve --mode development --fix",
"serve:stage": "vue-cli-service serve --mode stage",
"serve:prod": "vue-cli-service serve --mode production",
"build": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode stage",
"build:dev": "vue-cli-service build --mode development",
"dev": "npm run serve:dev",
"stage": "npm run serve:stage",
"prod": "npm run serve:prod",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.4",
"element-ui": "^2.13.1",
"vue": "^2.6.11",
"vue-router": "^3.1.6",
"vuex": "^3.1.3"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.3.0",
"@vue/cli-plugin-eslint": "~4.3.0",
"@vue/cli-plugin-router": "~4.3.0",
"@vue/cli-plugin-vuex": "~4.3.0",
"@vue/cli-service": "~4.3.0",
"@vue/eslint-config-airbnb": "^5.0.2",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-vue": "^6.2.2",
"lint-staged": "^9.5.0",
"node-sass": "^4.14.1",
"sass": "^1.26.8",
"sass-loader": "^8.0.2",
"validate-commit-msg": "^2.14.0",
"vue-template-compiler": "^2.6.11"
},
"gitHooks": {
"pre-commit": "lint-staged",
"commit-msg": "validate-commit-msg"
},
"lint-staged": {
"*.{js,jsx,vue}": [
"vue-cli-service lint",
"git add"
]
},
"description": "极师通教研项目脚手架升级",
"author": "huanglu"
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
<template>
<div id="app">
<gk-header />
<div id="nav" class="wrap">
<router-link to="/cart"> cart </router-link><br>
<router-link to="/home"> home </router-link><br>
<router-link to="/about"> about </router-link><br>
</div>
<keep-alive>
<router-view v-if="$route.meta.keepAlive"/>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"/>
</div>
</template>
<script>
import { mapMutations } from 'vuex';
import { login, userinfo } from '@/api';
import GkHeader from '@/components/Header'
export default {
data() {
return {
name: 'sfsfs'
}
},
components: {
GkHeader
},
mounted() {
login('huanglu', '123').then((res) => {
console.log(res);
});
userinfo({ id: '2424' }).then((res) => {
console.log('userinfo ----> ', res);
});
},
methods: {
...mapMutations(['changeName']),
},
};
</script>
<style lang="scss">
.wrap {
color: $geekColor;
}
body {
background: #1438ED;
}
</style>
import { get, post } from '@/utils/request';
export const login = (username, password) => post('/login', { username, password });
export const userinfo = (params) => get('/userinfo', params);
/* mixinx */
.bordered {
border-top: solid 1px black;
}
$good: 'red';
$geekColor: yellow;
<template>
<div class="gk-header">
<img src="https://geek.jkwljy.com/signin/img/LOGO.d1920f05.png">
</div>
</template>
<script>
export default {
components: {},
data() {
return {};
},
methods: {
},
mounted() {
}
}
</script>
<style lang='scss' scoped>
.gk-header {
display: flex;
flex-flow: row;
align-items: center;
background: #1438ED;
}
</style>
\ No newline at end of file
<template>
<div class="hello">
this is helloworld components
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String,
},
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
import HelloWorld from './hello-world';
export { HelloWorld };
import Vue from 'vue';
import ElementUI from 'element-ui';
import router from '@/router';
import store from '@/store';
import App from './App.vue';
Vue.config.productionTip = false;
Vue.use(ElementUI);
new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app')
import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '@/views/home';
const Cart = () => import('@/views/cart');
Vue.use(VueRouter);
// 单入口路由配置
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/cart',
name: 'Cart',
component: Cart
}
];
const router = new VueRouter({
mode: 'hash',
base: process.env.BASE_URL,
routes
});
export default router;
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
const reqiureContext = require.context('./modules', false, /\.js$/);
const modules = {};
reqiureContext.keys().forEach((key) => {
const name = key.slice(2, -3); // 得到 state的名称
const moduleConfig = reqiureContext(key).default || reqiureContext(key);
modules[name] = moduleConfig;
});
export default new Vuex.Store({
namespaced: true,
modules: {
...modules,
},
});
const state = {
username: 'zhaoting',
address: '',
token: '',
};
const mutations = {
changeName(state, payload) {
state.username = payload;
},
};
const getters = {
currentUsername: (state) => state.username,
};
export default {
state,
getters,
mutations,
};
const state = {
carts: [],
};
const actions = {
addCart({ commit }, cart) {
setTimeout(() => {
commit('addCart', cart);
}, 1000);
},
deleteCart({ commit }, id) {
setTimeout(() => {
commit('deleteCart', id);
}, 1000);
},
deleteAll({ commit }) {
setTimeout(() => {
commit('deleteAll');
}, 1000);
},
};
const mutations = {
addCart(state, product) {
const { carts } = state;
carts.push(product);
state.carts = [...carts];
},
deleteCart(state, id) {
const carts = [...state.carts.filter((cart) => cart.id !== id)];
state.carts = carts;
},
deleteAll() {
state.carts = [];
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};
import axios from 'axios';
const http = axios.create({
baseUrl: process.env.VUE_APP_API_HOST || process.env.BASE_URL
})
http.defaults.timeout = 10000;
// 响应拦截器
http.interceptors.response.use(
(response) => {
if (response.status >= 200 && response.status <= 299) {
// 配置响应
return Promise.resolve(response.data);
}
// TODO: 其他配置
return Promise.reject(response.data);
},
(error) => {
if (error.response.status) {
Promise.reject('请求失败');
}
},
);
http.interceptors.request.use(
(config) => {
// 设置token 或者 全局参数, headers等
config.headers = { 'Content-Type': 'application/json' };
return config;
},
(err) => Promise.reject(err),
);
/**
* 封装get方法
* @param url
* @param params
* @returns {Promise}
*/
export function get(api, params = {}) {
return http.get(api, { params });
}
/**
* 封装post请求
* @param url
* @param data
* @returns {Promise}
*/
export function post(api, data = {}) {
return http.post(api, data);
}
/**
* 封装patch请求
* @param url
* @param data
* @returns {Promise}
*/
export function patch(api, data = {}) {
return http.patch(api, data);
}
/**
* 封装put请求
* @param url
* @param data
* @returns {Promise}
*/
export function put(api, data = {}) {
return http.put(api, data);
}
/*
* @Author: jiangang
* @Date: 2018-09-06 17:29:35
* @Last Modified by: jiangang
* @Last Modified time: 2018-09-06 17:30:02
*/
/**
* 设置本地缓存
* @param {string} key
* @param {any} val
*/
export function setStorage(key, val) {
localStorage.setItem(key, JSON.stringify(val))
}
/**
* 获取本地缓存
* @param {string} key
*/
export function getStorage(key) {
const val = localStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
* 移除某一项缓存
* @param {string} key
*/
export function removeStorage(key) {
localStorage.removeItem(key)
}
/**
* 清除所有缓存
*/
export function clearStorage() {
localStorage.clear()
}
/**
* 设置本地临时缓存
* @param {string} key
* @param {any} val
*/
export function setSession(key, val) {
sessionStorage.setItem(key, JSON.stringify(val))
}
/**
* 获取本地临时缓存
* @param {string} key
*/
export function getSession(key) {
const val = sessionStorage.getItem(key)
return val === 'undefined' ? '' : JSON.parse(val)
}
/**
* 移除某一项临时缓存
* @param {string} key
*/
export function removeSession(key) {
sessionStorage.removeItem(key)
}
/**
* 清除所有临时缓存
*/
export function clearSession() {
sessionStorage.clear()
}
\ No newline at end of file
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
<template>
<div class='cartpage'>
<h1 v-for="item in carts" :key="item.id">
{{ JSON.stringify(item) }}
</h1>
<div>
<button @click="addCartInpage">add</button>
<button @click="deleteOne">deleteOne</button>
<button @click="deleteCartInpage">deleteAll</button>
</div>
</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
export default {
name: 'cart',
// import引入的组件需要注入到对象中才能使用
components: {
},
data() {
// 这里存放数据
return {
};
},
computed: {
...mapState({
carts: (state) => state.cart.carts,
}),
},
watch: {},
methods: {
...mapActions(['cart/addCart', 'cart/deleteAll', 'cart/deleteCart']),
addCartInpage() {
if (!this.addIndex) this.addIndex = 1;
this['cart/addCart']({ id: this.addIndex, cart: 'sfshfksfhs' });
this.addIndex += 1;
},
deleteCartInpage() {
if (!this.deleteIndex) {
this.deleteIndex = 1;
}
this['cart/deleteAll'](this.deleteIndex);
this.deleteIndex += 1;
},
deleteOne() {
}
},
created() {
},
mounted() {
},
};
</script>
<style lang='scss' scoped>
</style>
<template>
<div class="home">
<button @click="$router.push('Cart')">cart</button>
<el-button type="primary" @click="show">show</el-button>
</div>
</template>
<script>
export default {
name: 'Home',
components: {
},
methods: {
show() {
this.$message({
type: 'info',
message: 'this is message',
});
},
},
};
</script>
// vue.config.js
const path = require('path');
const mock = require('./mock');
const config = require('./config');
module.exports = {
css: {
loaderOptions: {
sass: {
prependData: `
@import "@/assets/styles/common.scss";
@import "@/assets/styles/variable.scss";
`
}
}
},
publicPath: config.publicPath || '/',
lintOnSave: true,
pages: config.pages,
devServer: {
proxy: config.proxy || {},
port: 8080,
open: true,
hot: true,
overlay: {
warnings: false,
errors: true
},
before(app) {
Object.keys(mock).forEach((key) => {
const mockValue = mock[key];
const result = typeof mockValue === 'function'
? mockValue
: (req, res) => res.json(mockValue);
if (/^(POST)./g.test(key)) {
app.post(key.replace('POST', '').trim(), result);
} else {
app.get(key.replace('GET', '').trim(), result);
}
});
}
}
};
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment