Skip to content

Commit e15d4b1

Browse files
committed
feat: upgrade nuxt.js to next before 1.0.0 released
1 parent 000f56f commit e15d4b1

File tree

10 files changed

+704
-990
lines changed

10 files changed

+704
-990
lines changed

client/assets/styles/main.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ header,
88
// max-height: 900px;
99
margin: 0 auto;
1010
}
11+
#__layout{
12+
height: 100%;
13+
}
1114
body {
1215
font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB',
1316
'Microsoft YaHei', SimSun, sans-serif;

client/middleware/check-auth.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { user as getUser } from '@/utils/auth'
22

3-
export default function ({ isServer, store, req, route, redirect }) {
3+
export default function ({ store, req, route, redirect }) {
44
// If nuxt generate, pass this middleware
5-
if (isServer && !req) return
6-
const user = getUser(isServer ? req : null)
5+
if (process.static) return
6+
const user = getUser(process.server ? req : null)
77
if (user && !store.state.authUser) {
88
store.commit('SET_USER', user)
99
} else if (!user && route.name !== 'login') {

client/pages/examples/activity/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<el-table-column prop="account" :label="$t('activity.account')" width="120" sortable>
1212
</el-table-column>
1313
<el-table-column :label="$t('activity.date')" width="120" sortable>
14-
<template scope="scope">{{ scope.row.date }}</template>
14+
<template slot-scope="scope">{{ scope.row.date }}</template>
1515
</el-table-column>
1616
<el-table-column prop="type" :label="$t('activity.type')" width="120" sortable>
1717
</el-table-column>
@@ -35,7 +35,7 @@
3535
<el-table-column type="selection" width="55">
3636
</el-table-column>
3737
<el-table-column type="expand">
38-
<template scope="props">
38+
<template slot-scope="props">
3939
<el-form label-position="left" inline class="demo-table-expand">
4040
<el-form-item :label="$t('activity.area')+':'">
4141
<span>{{ props.row.region }}</span>
@@ -55,15 +55,15 @@
5555
<el-table-column prop="account" :label="$t('activity.account')">
5656
</el-table-column>
5757
<el-table-column :label="$t('activity.date')">
58-
<template scope="scope">{{ scope.row.date }}</template>
58+
<template slot-scope="scope">{{ scope.row.date }}</template>
5959
</el-table-column>
6060
<el-table-column
6161
prop="type"
6262
:label="$t('activity.type')"
6363
:filters="[{ text: '优惠', value: '价格优惠' }, { text: '权限', value: '价格权益' }]"
6464
:filter-method="filterTag"
6565
filter-placement="bottom-end">
66-
<template scope="tag">
66+
<template slot-scope="tag">
6767
<el-tag
6868
:type="tag.row.type === '价格优惠' ? 'primary' : 'success'"
6969
close-transition>{{tag.row.type}}</el-tag>
@@ -90,7 +90,7 @@ import Component from 'class-component'
9090
export default class Example extends Vue {
9191
selections = []
9292
93-
async asyncData ({ isServer }) {
93+
async asyncData () {
9494
let {data: activities} = await axios.get('/hpi/activities')
9595
return {activities}
9696
}

client/pages/examples/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@
8080
</el-input>
8181
</el-col>
8282
<el-col :offset="2" :span="6" :xs="22">
83-
<el-input :placeholder="$t('example.inPh')" v-model="restaurant">
83+
<!-- <el-input :placeholder="$t('example.inPh')" v-model="restaurant">
8484
<el-select class="input-sel" v-model="restOptions" slot="prepend" :placeholder="$t('example.selPh')">
8585
<el-option label="餐厅名" value="1"></el-option>
8686
<el-option label="订单号" value="2"></el-option>
8787
<el-option label="用户电话" value="3"></el-option>
8888
</el-select>
8989
<el-button slot="append" icon="search"></el-button>
90-
</el-input>
90+
</el-input> -->
9191
</el-col>
9292
<el-col :offset="2" :span="6" :xs="22">
9393
<el-select v-model="multiFood" multiple :placeholder="$t('example.selPh')">

client/plugins/axios-defaults.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { defaultHeader, clientToken } from '@/utils/auth'
33

44
const PORT = process.env.PORT || '3000'
55

6-
export default ({ req, isServer, redirect }) => {
7-
if (!isServer) {
6+
export default ({ req, redirect }) => {
7+
if (process.client) {
88
defaultHeader(clientToken())
99
axios.interceptors.response.use(
1010
response => response,
@@ -19,10 +19,8 @@ export default ({ req, isServer, redirect }) => {
1919
return Promise.reject(error)
2020
}
2121
)
22-
}
23-
axios.defaults.timeout = 5000
24-
// for generate
25-
if (isServer && !req) {
22+
} else {
2623
axios.defaults.baseURL = `http://127.0.0.1:${PORT}`
2724
}
25+
axios.defaults.timeout = 5000
2826
}

client/plugins/i18n.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import Negotiator from 'negotiator'
44

55
Vue.use(VueI18n)
66

7-
export default ({ app, store, isServer, req }) => {
8-
if (isServer && req) {
7+
export default ({ app, store, req }) => {
8+
if (process.server) {
99
const negotiator = new Negotiator(req)
1010
const lang = negotiator.language(store.state.locales)
1111
store.commit('SET_LANG', lang || 'zh')

nuxt.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
babel: {
3535
plugins: ['transform-decorators-legacy', 'transform-class-properties']
3636
},
37-
extend (config, { dev, isClient }) {
37+
extend (config, { isDev }) {
3838
config.resolve.alias['class-component'] = '@/plugins/class-component'
3939
},
4040
vendor: [

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
"bunyan": "^1.8.12",
4242
"chart.js": "^2.7.1",
4343
"cross-env": "^5.1.0",
44-
"element-ui": "^1.4.8",
44+
"element-ui": "^1.4.12",
4545
"js-cookie": "^2.2.0",
4646
"js-yaml": "^3.9.1",
4747
"jwt-decode": "^2.2.0",
4848
"koa": "^2.4.1",
4949
"koa-body": "^2.3.0",
50-
"koa-bunyan": "^1.0.0",
50+
"koa-bunyan": "^1.0.1",
5151
"koa-bunyan-logger": "^2.0.0",
5252
"koa-compose": "^4.0.0",
5353
"koa-compress": "^2.0.0",
@@ -59,13 +59,13 @@
5959
"moment": "^2.19.2",
6060
"negotiator": "^0.6.1",
6161
"normalize.css": "^7.0.0",
62-
"nuxt": "^1.0.0-rc11",
62+
"nuxt": "^1.0.0-gh-0b9cd1b",
6363
"svg-captcha": "^1.3.11",
6464
"vue-chartjs": "^3.0.2",
65-
"vue-class-component": "^5.0.1",
65+
"vue-class-component": "^6.1.1",
6666
"vue-clipboards": "^1.2.0",
6767
"vue-i18n": "^7.3.2",
68-
"vuex-class": "^0.2.0",
68+
"vuex-class": "^0.3.0",
6969
"xmlify": "^1.1.0"
7070
},
7171
"devDependencies": {
@@ -77,7 +77,8 @@
7777
"babel-plugin-transform-decorators-legacy": "^1.3.4",
7878
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
7979
"babel-plugin-transform-object-rest-spread": "^6.26.0",
80-
"eslint": "^4.12.0",
80+
"babel-plugin-transform-runtime": "^6.23.0",
81+
"eslint": "^4.13.0",
8182
"eslint-config-standard": "^10.2.1",
8283
"eslint-plugin-html": "^4.0.1",
8384
"eslint-plugin-import": "^2.8.0",
@@ -88,16 +89,16 @@
8889
"lint-staged": "^5.0.0",
8990
"moxios": "^0.4.0",
9091
"node-sass": "^4.7.2",
91-
"nodemon": "^1.11.0",
92+
"nodemon": "^1.12.5",
9293
"progress-bar-webpack-plugin": "^1.10.0",
9394
"sass-loader": "^6.0.6",
9495
"standard-version": "^4.2.0",
9596
"uglifyjs-webpack-plugin": "^1.1.1",
96-
"webpack": "^3.5.5",
97+
"webpack": "^3.10.0",
9798
"webpack-node-externals": "^1.6.0"
9899
},
99100
"engines": {
100-
"node": ">=7.6.0",
101-
"npm": ">=4.0.0"
101+
"node": ">=8.0.0",
102+
"npm": ">=5.0.0"
102103
}
103104
}

server/app.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import Koa from 'koa'
22
import { Nuxt, Builder } from 'nuxt'
3-
import axios from 'axios'
43
import bunyan from 'bunyan'
54
import mkdirp from 'mkdirp'
65
import koaBunyan from 'koa-bunyan'
@@ -27,8 +26,6 @@ async function start () {
2726

2827
app.keys = ['hare-server']
2928
config.dev = !(app.env === 'production')
30-
axios.defaults.baseURL = `http://127.0.0.1:${port}`
31-
3229
// logging
3330
let logDir = process.env.LOG_DIR || (isWin ? 'C:\\\\log' : '/var/tmp/log')
3431
mkdirp.sync(logDir)
@@ -68,11 +65,6 @@ async function start () {
6865
})
6966

7067
const nuxt = new Nuxt(config)
71-
nuxt.showOpen = () => {
72-
const _host = host === '0.0.0.0' ? 'localhost' : host
73-
// eslint-disable-next-line no-console
74-
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
75-
}
7668
// Build only in dev mode
7769
if (config.dev) {
7870
const devConfigs = config.development
@@ -141,6 +133,9 @@ async function start () {
141133
})
142134

143135
app.listen(port, host)
136+
const _host = host === '0.0.0.0' ? 'localhost' : host
137+
// eslint-disable-next-line no-console
138+
console.log('\n' + chalk.bgGreen.black(' OPEN ') + chalk.green(` http://${_host}:${port}\n`))
144139
}
145140

146141
start()

0 commit comments

Comments
 (0)