Browse Source

更改isClient isSever

Administrator 7 years ago
parent
commit
84fe151037
7 changed files with 18 additions and 19 deletions
  1. 2 2
      middleware/authenticated.js
  2. 3 3
      middleware/check-auth.js
  3. 3 3
      middleware/wechatInfo.js
  4. 2 2
      nuxt.config.js
  5. 3 4
      plugins/axios.js
  6. 3 3
      store/index.js
  7. 2 2
      store/product.js

+ 2 - 2
middleware/authenticated.js

@@ -1,6 +1,6 @@
-export default function ({ isServer, store, req, redirect, route }) {
+export default function ({ store, req, redirect, route }) {
   // If nuxt generate, pass this middleware
-  if (isServer && !req) return
+  if (process.server && !req) return
   if (!store.state.option.user.logged) {
     let ua = store.state.option.userAgent.toLowerCase()
     if (ua.match(/micromessenger/i) && ua.match(/micromessenger/i)[0] === 'micromessenger' && req.url.indexOf('?code') === -1) {

+ 3 - 3
middleware/check-auth.js

@@ -1,9 +1,9 @@
 import { getAuthInfo } from '~/utils/client-auth'
 
-export default function ({ isServer, store, req }) {
+export default function ({ store, req }) {
   // If nuxt generate, pass this middleware
-  if (isServer && !req) return
-  if (isServer) {
+  if (process.server && !req) return
+  if (process.server) {
     store.dispatch('loadUserInfo')
   } else {
     getAuthInfo()

+ 3 - 3
middleware/wechatInfo.js

@@ -1,6 +1,6 @@
-export default function ({ isServer, store, req, redirect, route }) {
-  if (isServer && !req) return
-  if (isServer) return
+export default function ({ store, req, redirect, route }) {
+  if (process.server && !req) return
+  if (process.server) return
   // nuxt拦截器 存在一个问题,如果进入到了判断的地方,一定需要做跳转路由相关操作,不然会出现404
   //  && window.__wxjs_environment !== 'miniprogram'
   if (!store.state.option.wechatInfo.data.openid) {

+ 2 - 2
nuxt.config.js

@@ -46,7 +46,7 @@ module.exports = {
     ** Run ESLINT on save
     */
     extractCSS: { allChunks: true },
-    extend(config, { isDev, isClient, isServer }) {
+    extend(config, { isDev }) {
       config.resolve.alias['~utils'] = path.join(__dirname, 'utils')
       config.resolve.alias['~components'] = path.join(__dirname, 'components')
       config.resolve.alias['~plugins'] = path.join(__dirname, 'plugins')
@@ -57,7 +57,7 @@ module.exports = {
       //   loader: 'style-loader!css-loader!sass-loader'
       // })
 
-      if (isClient) {
+      if (process.client) {
         config.module.rules.push({
           enforce: 'pre',
           test: /\.(js|vue)$/,

+ 3 - 4
plugins/axios.js

@@ -9,12 +9,11 @@ const service = axios.create({
 
 let reqCount = 0 // 请求计数器
 
-const isServer = typeof window === 'undefined'
 service.interceptors.request.use(config => {
   // is server render, use ${baseUrl} directly rather than ${proxyUrl}
   config.url = config.url || '/'
   reqCount++
-  if (isServer) {
+  if (process.server) {
     if (config.url.indexOf('/inquiry') === 0) {
       config.url = process.env.commonUrl + config.url
     } else if (config.url.indexOf('/productsuer') === 0) {
@@ -59,12 +58,12 @@ service.interceptors.response.use(response => {
       }
     }
   }
-  if (--reqCount <= 0 && !isServer) {
+  if (--reqCount <= 0 && !process.server) {
     document.getElementById('loading').setAttribute('class', 'loading')
   }
   return response
 }, error => {
-  if (--reqCount <= 0 && !isServer) {
+  if (--reqCount <= 0 && !process.server) {
     document.getElementById('loading').setAttribute('class', 'loading')
   }
   return Promise.reject(error)

+ 3 - 3
store/index.js

@@ -25,11 +25,11 @@ function loadBrandComponent({ commit }, params = {}) {
 
 export const actions = {
   // 全局服务初始化
-  nuxtServerInit(store, { params, route, isDev, isServer, req }) {
+  nuxtServerInit(store, { params, route, isDev, req }) {
     // 检查设备类型
-    const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
+    const userAgent = process.server ? req.headers['user-agent'] : navigator.userAgent
     const isMobile = /(iPhone|iPad|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
-    const cookie = isServer ? req.headers['cookie'] : null
+    const cookie = process.server ? req.headers['cookie'] : null
     store.commit('option/SET_MOBILE_LAYOUT', isMobile)
     store.commit('option/SET_USER_AGENT', userAgent)
     store.commit('option/SET_COOKIES', cookie)

+ 2 - 2
store/product.js

@@ -13,9 +13,9 @@ function saveStores ({ commit }, params = {}) {
 
 export const actions = {
   // 全局服务初始化
-  nuxtServerInit (store, { params, route, isServer, req }) {
+  nuxtServerInit (store, { params, route, req }) {
     // 检查设备类型
-    const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
+    const userAgent = process.server ? req.headers['user-agent'] : navigator.userAgent
     const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
     store.commit('option/SET_MOBILE_LAYOUT', isMobile)
     store.commit('option/SET_USER_AGENT', userAgent)