Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加vuex和axioss #1482

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cd _book
git init
git add -A
git commit -m 'update book'
git push -f git@github.com:vuejs-templates/webpack.git master:gh-pages
git push -f git@github.com:git-wlking/VUT.git master:git-wlking
23 changes: 23 additions & 0 deletions meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ module.exports = {
type: 'confirm',
message: 'Install vue-router?',
},
axios: {
when: 'isNotTest',
type: 'confirm',
message: 'Install axios?',
},
elementui: {
when: 'isNotTest',
type: 'confirm',
message: 'Install element-ui?',
},
vuex: {
when: 'isNotTest',
type: 'confirm',
message: 'Install vuex?',
},
sass: {
when: 'isNotTest',
type: 'confirm',
message: 'Install sass?',
},
lint: {
when: 'isNotTest',
type: 'confirm',
Expand Down Expand Up @@ -170,6 +190,9 @@ module.exports = {
'test/unit/setup.js': "unit && runner === 'jest'",
'test/e2e/**/*': 'e2e',
'src/router/**/*': 'router',
'src/store/**/*': 'vuex',
'src/api/**/*': 'axios',
'src/assets/style/*': 'axios',
},
complete: function(data, { chalk }) {
const green = chalk.green
Expand Down
9 changes: 8 additions & 1 deletion template/build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ exports.cssLoaders = function (options) {
postcss: generateLoaders(),
less: generateLoaders('less'),
sass: generateLoaders('sass', { indentedSyntax: true }),
scss: generateLoaders('sass'),
scss: generateLoaders('sass'){{#sass}}.concat(
{
loader: 'sass-resources-loader',
options: {
resources: path.resolve(__dirname, '../src/assets/style/index.scss')
}
}
),{{/sass}}
stylus: generateLoaders('stylus'),
styl: generateLoaders('stylus')
}
Expand Down
6 changes: 6 additions & 0 deletions template/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ module.exports = {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
},
{{#sass}}
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}
{{/sass}}
]
},
node: {
Expand Down
12 changes: 10 additions & 2 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "{{ name }}",
"version": "1.0.0",
"description": "{{ description }}",
"author": "{{ author }}",
"author": "glodon-lo-{{ author }}",
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
Expand All @@ -26,7 +26,10 @@
},
"dependencies": {
"vue": "^2.5.2"{{#router}},
"vue-router": "^3.0.1"{{/router}}
"vue-router": "^3.0.1"{{/router}}{{#axios}},
"axios": "^0.18.0"{{/axios}} {{#vuex}},
"vuex": "^2.4.1"{{/vuex}}{{#elementui}},
"element-ui": "^2.5.4"{{/elementui}}
},
"devDependencies": {
{{#lint}}
Expand Down Expand Up @@ -82,6 +85,11 @@
"nightwatch": "^0.9.12",
"selenium-server": "^3.0.1",
{{/e2e}}
{{#sass}}
"sass-loader": "^7.1.0",
"sass-resources-loader": "^2.0.0",
"node-sass": "^4.11.0",
{{/sass}}
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
Expand Down
70 changes: 70 additions & 0 deletions template/src/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* @Author: luox-e
* @Date: 2019-02-19 14:29:36
* @Last Modified by: glodon
* @Last Modified time: 2019-02-19 14:43:08
*/
import axios from 'axios'
import {
MessageBox
} from 'element-ui'

let api = '/api'
if (process.env.NODE_ENV === 'development') {
api = '/api/'
}

const baseURL = api
const Axios = axios.create({
baseURL: baseURL, // 因为我本地做了反向代理
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
})
Axios.interceptors.response.use(
function (response) {
// 返回响应时做一些处理
if (
response.request.responseURL &&
response.request.responseURL.indexOf(
'Services/Identification/Server/login.ashx'
) > 0
) {
this.$router.push({
path: '/login'
})
// window.location = '/Services/Identification/Server/Login.aspx'
} else {
if (response) {
return response.data
} else {
const msgConfig = {
title: '系统错误',
message: response.data.ResultDetailMsg
}
MessageBox(msgConfig)
}
}
},
function (error) {
if (error.response) {
// const msgConfig = {
// title: '请求错误',
// message: error.response.status
// }
// MessageBox(msgConfig)
}
// 当响应异常时做一些处理
return Promise.reject(error)
}
)

// 对axios的实例重新封装成一个plugin ,方便 Vue.use(xxxx)
export default {
install: function (Vue, Option) {
Object.defineProperty(Vue.prototype, '$http', {
value: Axios
})
},
baseURL
}
20 changes: 20 additions & 0 deletions template/src/assets/style/base.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @Author: luox-e
* @Date: 2019-02-19 11:00:02
* @Last Modified by: glodon
* @Last Modified time: 2019-02-19 14:26:21
*/

//写一些我们需要全局设置的一些基本样式,例如清除浮动

//清除浮动;
%clearfix {
*zoom: 1;
&:before, &:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
}
20 changes: 20 additions & 0 deletions template/src/assets/style/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @Author: luox-e
* @Date: 2019-02-19 11:00:19
* @Last Modified by: glodon
* @Last Modified time: 2019-02-19 14:11:20
*/
//是我们scss的总体引入文件,将我们所有的公共scss引入,这样一来我们只要全局引用index.scss文件就可以了
//minxin
@import './mixin.scss';
//全局设置的基本样式
@import './base.scss';
/* element UI 样式总控*/

/* 改变主题色变量 */
$--color-primary: #1D8CE0;

/* 改变 icon 字体路径变量,必需 */
$--font-path: '~element-ui/lib/theme-chalk/fonts';

@import "~element-ui/packages/theme-chalk/src/index";
7 changes: 7 additions & 0 deletions template/src/assets/style/mixin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* @Author: luox-e
* @Date: 2019-02-19 11:00:14
* @Last Modified by: glodon
* @Last Modified time: 2019-02-19 11:00:14
*/
// 这个文件就是我们scss的mixin文件了
21 changes: 21 additions & 0 deletions template/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,36 @@ import App from './App'
{{#router}}
import router from './router'
{{/router}}
{{#vuex}}
import store from './store'
{{/vuex}}
{{#axios}}
import axiosPlugin from './api'
{{/axios}}
{{#elementui}}
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
{{/elementui}}

Vue.config.productionTip = false

{{#axios}}
Vue.use(axiosPlugin)
{{/axios}}

{{#elementui}}
Vue.use(ElementUI);
{{/elementui}}

/* eslint-disable no-new */
new Vue({
el: '#app',
{{#router}}
router,
{{/router}}
{{#vuex}}
store,
{{/vuex}}
{{#if_eq build "runtime"}}
render: h => h(App)
{{/if_eq}}
Expand Down
8 changes: 8 additions & 0 deletions template/src/store/State.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
layoutConfig: {
colNum: 120,
rowHeight: 10,
margin: [0, 0]
},
currentProtal: localStorage.getItem('currentPortal') ? JSON.parse(localStorage.getItem('currentPortal')) : {}
}
Empty file added template/src/store/action.js
Empty file.
15 changes: 15 additions & 0 deletions template/src/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Vue from 'vue'
import Vuex from 'vuex'
import state from './State.js'
import mutations from './mutations.js'

Vue.use(Vuex)

export default new Vuex.Store({
state,
mutations,
modules: {

},
strict: process.env.NODE_ENV !== 'production' // 严格模式
})
6 changes: 6 additions & 0 deletions template/src/store/mutations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
updateCurrentProtal(state, currentProtal) {
state.currentProtal = currentProtal
localStorage.setItem('currentPortal', JSON.stringify({...currentProtal}))
}
}