ssr 渲染
|
@ -16,7 +16,7 @@
|
|||
"core-js": "^3.15.1",
|
||||
"element-ui": "^2.15.2",
|
||||
"js-cookie": "^2.2.1",
|
||||
"nuxt": "^2.15.7",
|
||||
"nuxt": "latest",
|
||||
"swiper": "^5.2.0",
|
||||
"vue-awesome-swiper": "^4.1.1"
|
||||
},
|
||||
|
|
|
@ -0,0 +1,219 @@
|
|||
import Vue from 'vue'
|
||||
import { decode, parsePath, withoutBase, withoutTrailingSlash, normalizeURL } from 'ufo'
|
||||
|
||||
import { getMatchedComponentsInstances, getChildrenComponentInstancesUsingFetch, promisify, globalHandleError, urlJoin, sanitizeComponent } from './utils'
|
||||
import NuxtError from '..\\layouts\\error.vue'
|
||||
import NuxtLoading from './components/nuxt-loading.vue'
|
||||
|
||||
import '..\\assets\\css\\element-variables.scss'
|
||||
|
||||
import '..\\assets\\css\\common.scss'
|
||||
|
||||
import '..\\assets\\css\\reset.scss'
|
||||
|
||||
import '..\\node_modules\\swiper\\css\\swiper.css'
|
||||
|
||||
import '..\\assets\\css\\element.scss'
|
||||
|
||||
import '..\\assets\\fonts\\iconfont.css'
|
||||
|
||||
import _6f6c098b from '..\\layouts\\default.vue'
|
||||
import _2d26a6af from '..\\layouts\\main.vue'
|
||||
import _ed36e90e from '..\\layouts\\street.vue'
|
||||
import _2d2a8cc1 from '..\\layouts\\user.vue'
|
||||
|
||||
const layouts = { "_default": sanitizeComponent(_6f6c098b),"_main": sanitizeComponent(_2d26a6af),"_street": sanitizeComponent(_ed36e90e),"_user": sanitizeComponent(_2d2a8cc1) }
|
||||
|
||||
export default {
|
||||
render (h, props) {
|
||||
const loadingEl = h('NuxtLoading', { ref: 'loading' })
|
||||
|
||||
const layoutEl = h(this.layout || 'nuxt')
|
||||
const templateEl = h('div', {
|
||||
domProps: {
|
||||
id: '__layout'
|
||||
},
|
||||
key: this.layoutName
|
||||
}, [layoutEl])
|
||||
|
||||
const transitionEl = h('transition', {
|
||||
props: {
|
||||
name: 'layout',
|
||||
mode: 'out-in'
|
||||
},
|
||||
on: {
|
||||
beforeEnter (el) {
|
||||
// Ensure to trigger scroll event after calling scrollBehavior
|
||||
window.$nuxt.$nextTick(() => {
|
||||
window.$nuxt.$emit('triggerScroll')
|
||||
})
|
||||
}
|
||||
}
|
||||
}, [templateEl])
|
||||
|
||||
return h('div', {
|
||||
domProps: {
|
||||
id: '__nuxt'
|
||||
}
|
||||
}, [
|
||||
loadingEl,
|
||||
|
||||
transitionEl
|
||||
])
|
||||
},
|
||||
|
||||
data: () => ({
|
||||
isOnline: true,
|
||||
|
||||
layout: null,
|
||||
layoutName: '',
|
||||
|
||||
nbFetching: 0
|
||||
}),
|
||||
|
||||
beforeCreate () {
|
||||
Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
|
||||
},
|
||||
created () {
|
||||
// Add this.$nuxt in child instances
|
||||
this.$root.$options.$nuxt = this
|
||||
|
||||
if (process.client) {
|
||||
// add to window so we can listen when ready
|
||||
window.$nuxt = this
|
||||
|
||||
this.refreshOnlineStatus()
|
||||
// Setup the listeners
|
||||
window.addEventListener('online', this.refreshOnlineStatus)
|
||||
window.addEventListener('offline', this.refreshOnlineStatus)
|
||||
}
|
||||
// Add $nuxt.error()
|
||||
this.error = this.nuxt.error
|
||||
// Add $nuxt.context
|
||||
this.context = this.$options.context
|
||||
},
|
||||
|
||||
async mounted () {
|
||||
this.$loading = this.$refs.loading
|
||||
},
|
||||
|
||||
watch: {
|
||||
'nuxt.err': 'errorChanged'
|
||||
},
|
||||
|
||||
computed: {
|
||||
isOffline () {
|
||||
return !this.isOnline
|
||||
},
|
||||
|
||||
isFetching () {
|
||||
return this.nbFetching > 0
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
refreshOnlineStatus () {
|
||||
if (process.client) {
|
||||
if (typeof window.navigator.onLine === 'undefined') {
|
||||
// If the browser doesn't support connection status reports
|
||||
// assume that we are online because most apps' only react
|
||||
// when they now that the connection has been interrupted
|
||||
this.isOnline = true
|
||||
} else {
|
||||
this.isOnline = window.navigator.onLine
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async refresh () {
|
||||
const pages = getMatchedComponentsInstances(this.$route)
|
||||
|
||||
if (!pages.length) {
|
||||
return
|
||||
}
|
||||
this.$loading.start()
|
||||
|
||||
const promises = pages.map(async (page) => {
|
||||
let p = []
|
||||
|
||||
// Old fetch
|
||||
if (page.$options.fetch && page.$options.fetch.length) {
|
||||
p.push(promisify(page.$options.fetch, this.context))
|
||||
}
|
||||
|
||||
if (page.$options.asyncData) {
|
||||
p.push(
|
||||
promisify(page.$options.asyncData, this.context)
|
||||
.then((newData) => {
|
||||
for (const key in newData) {
|
||||
Vue.set(page.$data, key, newData[key])
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// Wait for asyncData & old fetch to finish
|
||||
await Promise.all(p)
|
||||
// Cleanup refs
|
||||
p = []
|
||||
|
||||
if (page.$fetch) {
|
||||
p.push(page.$fetch())
|
||||
}
|
||||
// Get all component instance to call $fetch
|
||||
for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) {
|
||||
p.push(component.$fetch())
|
||||
}
|
||||
|
||||
return Promise.all(p)
|
||||
})
|
||||
try {
|
||||
await Promise.all(promises)
|
||||
} catch (error) {
|
||||
this.$loading.fail(error)
|
||||
globalHandleError(error)
|
||||
this.error(error)
|
||||
}
|
||||
this.$loading.finish()
|
||||
},
|
||||
errorChanged () {
|
||||
if (this.nuxt.err) {
|
||||
if (this.$loading) {
|
||||
if (this.$loading.fail) {
|
||||
this.$loading.fail(this.nuxt.err)
|
||||
}
|
||||
if (this.$loading.finish) {
|
||||
this.$loading.finish()
|
||||
}
|
||||
}
|
||||
|
||||
let errorLayout = (NuxtError.options || NuxtError).layout;
|
||||
|
||||
if (typeof errorLayout === 'function') {
|
||||
errorLayout = errorLayout(this.context)
|
||||
}
|
||||
|
||||
this.setLayout(errorLayout)
|
||||
}
|
||||
},
|
||||
|
||||
setLayout (layout) {
|
||||
if (!layout || !layouts['_' + layout]) {
|
||||
layout = 'default'
|
||||
}
|
||||
this.layoutName = layout
|
||||
this.layout = layouts['_' + layout]
|
||||
return this.layout
|
||||
},
|
||||
loadLayout (layout) {
|
||||
if (!layout || !layouts['_' + layout]) {
|
||||
layout = 'default'
|
||||
}
|
||||
return Promise.resolve(layouts['_' + layout])
|
||||
},
|
||||
},
|
||||
|
||||
components: {
|
||||
NuxtLoading
|
||||
}
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
import Axios from 'axios'
|
||||
import defu from 'defu'
|
||||
|
||||
// Axios.prototype cannot be modified
|
||||
const axiosExtra = {
|
||||
setBaseURL (baseURL) {
|
||||
this.defaults.baseURL = baseURL
|
||||
},
|
||||
setHeader (name, value, scopes = 'common') {
|
||||
for (const scope of Array.isArray(scopes) ? scopes : [ scopes ]) {
|
||||
if (!value) {
|
||||
delete this.defaults.headers[scope][name];
|
||||
continue
|
||||
}
|
||||
this.defaults.headers[scope][name] = value
|
||||
}
|
||||
},
|
||||
setToken (token, type, scopes = 'common') {
|
||||
const value = !token ? null : (type ? type + ' ' : '') + token
|
||||
this.setHeader('Authorization', value, scopes)
|
||||
},
|
||||
onRequest(fn) {
|
||||
this.interceptors.request.use(config => fn(config) || config)
|
||||
},
|
||||
onResponse(fn) {
|
||||
this.interceptors.response.use(response => fn(response) || response)
|
||||
},
|
||||
onRequestError(fn) {
|
||||
this.interceptors.request.use(undefined, error => fn(error) || Promise.reject(error))
|
||||
},
|
||||
onResponseError(fn) {
|
||||
this.interceptors.response.use(undefined, error => fn(error) || Promise.reject(error))
|
||||
},
|
||||
onError(fn) {
|
||||
this.onRequestError(fn)
|
||||
this.onResponseError(fn)
|
||||
},
|
||||
create(options) {
|
||||
return createAxiosInstance(defu(options, this.defaults))
|
||||
}
|
||||
}
|
||||
|
||||
// Request helpers ($get, $post, ...)
|
||||
for (const method of ['request', 'delete', 'get', 'head', 'options', 'post', 'put', 'patch']) {
|
||||
axiosExtra['$' + method] = function () { return this[method].apply(this, arguments).then(res => res && res.data) }
|
||||
}
|
||||
|
||||
const extendAxiosInstance = axios => {
|
||||
for (const key in axiosExtra) {
|
||||
axios[key] = axiosExtra[key].bind(axios)
|
||||
}
|
||||
}
|
||||
|
||||
const createAxiosInstance = axiosOptions => {
|
||||
// Create new axios instance
|
||||
const axios = Axios.create(axiosOptions)
|
||||
axios.CancelToken = Axios.CancelToken
|
||||
axios.isCancel = Axios.isCancel
|
||||
|
||||
// Extend axios proto
|
||||
extendAxiosInstance(axios)
|
||||
|
||||
// Intercept to apply default headers
|
||||
axios.onRequest((config) => {
|
||||
config.headers = { ...axios.defaults.headers.common, ...config.headers }
|
||||
})
|
||||
|
||||
// Setup interceptors
|
||||
|
||||
setupProgress(axios)
|
||||
|
||||
return axios
|
||||
}
|
||||
|
||||
const setupProgress = (axios) => {
|
||||
if (process.server) {
|
||||
return
|
||||
}
|
||||
|
||||
// A noop loading inteterface for when $nuxt is not yet ready
|
||||
const noopLoading = {
|
||||
finish: () => { },
|
||||
start: () => { },
|
||||
fail: () => { },
|
||||
set: () => { }
|
||||
}
|
||||
|
||||
const $loading = () => {
|
||||
const $nuxt = typeof window !== 'undefined' && window['$nuxt']
|
||||
return ($nuxt && $nuxt.$loading && $nuxt.$loading.set) ? $nuxt.$loading : noopLoading
|
||||
}
|
||||
|
||||
let currentRequests = 0
|
||||
|
||||
axios.onRequest(config => {
|
||||
if (config && config.progress === false) {
|
||||
return
|
||||
}
|
||||
|
||||
currentRequests++
|
||||
})
|
||||
|
||||
axios.onResponse(response => {
|
||||
if (response && response.config && response.config.progress === false) {
|
||||
return
|
||||
}
|
||||
|
||||
currentRequests--
|
||||
if (currentRequests <= 0) {
|
||||
currentRequests = 0
|
||||
$loading().finish()
|
||||
}
|
||||
})
|
||||
|
||||
axios.onError(error => {
|
||||
if (error && error.config && error.config.progress === false) {
|
||||
return
|
||||
}
|
||||
|
||||
currentRequests--
|
||||
|
||||
if (Axios.isCancel(error)) {
|
||||
if (currentRequests <= 0) {
|
||||
currentRequests = 0
|
||||
$loading().finish()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
$loading().fail()
|
||||
$loading().finish()
|
||||
})
|
||||
|
||||
const onProgress = e => {
|
||||
if (!currentRequests || !e.total) {
|
||||
return
|
||||
}
|
||||
const progress = ((e.loaded * 100) / (e.total * currentRequests))
|
||||
$loading().set(Math.min(100, progress))
|
||||
}
|
||||
|
||||
axios.defaults.onUploadProgress = onProgress
|
||||
axios.defaults.onDownloadProgress = onProgress
|
||||
}
|
||||
|
||||
export default (ctx, inject) => {
|
||||
// runtimeConfig
|
||||
const runtimeConfig = ctx.$config && ctx.$config.axios || {}
|
||||
// baseURL
|
||||
const baseURL = process.browser
|
||||
? (runtimeConfig.browserBaseURL || runtimeConfig.browserBaseUrl || runtimeConfig.baseURL || runtimeConfig.baseUrl || 'http://localhost:8000/')
|
||||
: (runtimeConfig.baseURL || runtimeConfig.baseUrl || process.env._AXIOS_BASE_URL_ || 'http://localhost:8000/')
|
||||
|
||||
// Create fresh objects for all default header scopes
|
||||
// Axios creates only one which is shared across SSR requests!
|
||||
// https://github.com/mzabriskie/axios/blob/master/lib/defaults.js
|
||||
const headers = {
|
||||
"common": {
|
||||
"Accept": "application/json, text/plain, */*"
|
||||
},
|
||||
"delete": {},
|
||||
"get": {},
|
||||
"head": {},
|
||||
"post": {},
|
||||
"put": {},
|
||||
"patch": {}
|
||||
}
|
||||
|
||||
const axiosOptions = {
|
||||
baseURL,
|
||||
headers
|
||||
}
|
||||
|
||||
// Proxy SSR request headers headers
|
||||
if (process.server && ctx.req && ctx.req.headers) {
|
||||
const reqHeaders = { ...ctx.req.headers }
|
||||
for (const h of ["accept","cf-connecting-ip","cf-ray","content-length","content-md5","content-type","host","x-forwarded-host","x-forwarded-port","x-forwarded-proto"]) {
|
||||
delete reqHeaders[h]
|
||||
}
|
||||
axiosOptions.headers.common = { ...reqHeaders, ...axiosOptions.headers.common }
|
||||
}
|
||||
|
||||
if (process.server) {
|
||||
// Don't accept brotli encoding because Node can't parse it
|
||||
axiosOptions.headers.common['accept-encoding'] = 'gzip, deflate'
|
||||
}
|
||||
|
||||
const axios = createAxiosInstance(axiosOptions)
|
||||
|
||||
// Inject axios to the context as $axios
|
||||
ctx.$axios = axios
|
||||
inject('axios', axios)
|
||||
}
|
|
@ -0,0 +1,687 @@
|
|||
import Vue from 'vue'
|
||||
import fetch from 'unfetch'
|
||||
import middleware from './middleware.js'
|
||||
import {
|
||||
applyAsyncData,
|
||||
promisify,
|
||||
middlewareSeries,
|
||||
sanitizeComponent,
|
||||
resolveRouteComponents,
|
||||
getMatchedComponents,
|
||||
getMatchedComponentsInstances,
|
||||
flatMapComponents,
|
||||
setContext,
|
||||
getLocation,
|
||||
compile,
|
||||
getQueryDiff,
|
||||
globalHandleError,
|
||||
isSamePath,
|
||||
urlJoin
|
||||
} from './utils.js'
|
||||
import { createApp, NuxtError } from './index.js'
|
||||
import fetchMixin from './mixins/fetch.client'
|
||||
import NuxtLink from './components/nuxt-link.client.js' // should be included after ./index.js
|
||||
|
||||
// Fetch mixin
|
||||
if (!Vue.__nuxt__fetch__mixin__) {
|
||||
Vue.mixin(fetchMixin)
|
||||
Vue.__nuxt__fetch__mixin__ = true
|
||||
}
|
||||
|
||||
// Component: <NuxtLink>
|
||||
Vue.component(NuxtLink.name, NuxtLink)
|
||||
Vue.component('NLink', NuxtLink)
|
||||
|
||||
if (!global.fetch) { global.fetch = fetch }
|
||||
|
||||
// Global shared references
|
||||
let _lastPaths = []
|
||||
let app
|
||||
let router
|
||||
let store
|
||||
|
||||
// Try to rehydrate SSR data from window
|
||||
const NUXT = window.__NUXT__ || {}
|
||||
|
||||
const $config = NUXT.config || {}
|
||||
if ($config._app) {
|
||||
__webpack_public_path__ = urlJoin($config._app.cdnURL, $config._app.assetsPath)
|
||||
}
|
||||
|
||||
Object.assign(Vue.config, {"silent":true,"performance":false})
|
||||
|
||||
const errorHandler = Vue.config.errorHandler || console.error
|
||||
|
||||
// Create and mount App
|
||||
createApp(null, NUXT.config).then(mountApp).catch(errorHandler)
|
||||
|
||||
function componentOption (component, key, ...args) {
|
||||
if (!component || !component.options || !component.options[key]) {
|
||||
return {}
|
||||
}
|
||||
const option = component.options[key]
|
||||
if (typeof option === 'function') {
|
||||
return option(...args)
|
||||
}
|
||||
return option
|
||||
}
|
||||
|
||||
function mapTransitions (toComponents, to, from) {
|
||||
const componentTransitions = (component) => {
|
||||
const transition = componentOption(component, 'transition', to, from) || {}
|
||||
return (typeof transition === 'string' ? { name: transition } : transition)
|
||||
}
|
||||
|
||||
const fromComponents = from ? getMatchedComponents(from) : []
|
||||
const maxDepth = Math.max(toComponents.length, fromComponents.length)
|
||||
|
||||
const mergedTransitions = []
|
||||
for (let i=0; i<maxDepth; i++) {
|
||||
// Clone original objects to prevent overrides
|
||||
const toTransitions = Object.assign({}, componentTransitions(toComponents[i]))
|
||||
const transitions = Object.assign({}, componentTransitions(fromComponents[i]))
|
||||
|
||||
// Combine transitions & prefer `leave` properties of "from" route
|
||||
Object.keys(toTransitions)
|
||||
.filter(key => typeof toTransitions[key] !== 'undefined' && !key.toLowerCase().includes('leave'))
|
||||
.forEach((key) => { transitions[key] = toTransitions[key] })
|
||||
|
||||
mergedTransitions.push(transitions)
|
||||
}
|
||||
return mergedTransitions
|
||||
}
|
||||
|
||||
async function loadAsyncComponents (to, from, next) {
|
||||
// Check if route changed (this._routeChanged), only if the page is not an error (for validate())
|
||||
this._routeChanged = Boolean(app.nuxt.err) || from.name !== to.name
|
||||
this._paramChanged = !this._routeChanged && from.path !== to.path
|
||||
this._queryChanged = !this._paramChanged && from.fullPath !== to.fullPath
|
||||
this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, from.query) : [])
|
||||
|
||||
if ((this._routeChanged || this._paramChanged) && this.$loading.start && !this.$loading.manual) {
|
||||
this.$loading.start()
|
||||
}
|
||||
|
||||
try {
|
||||
if (this._queryChanged) {
|
||||
const Components = await resolveRouteComponents(
|
||||
to,
|
||||
(Component, instance) => ({ Component, instance })
|
||||
)
|
||||
// Add a marker on each component that it needs to refresh or not
|
||||
const startLoader = Components.some(({ Component, instance }) => {
|
||||
const watchQuery = Component.options.watchQuery
|
||||
if (watchQuery === true) {
|
||||
return true
|
||||
}
|
||||
if (Array.isArray(watchQuery)) {
|
||||
return watchQuery.some(key => this._diffQuery[key])
|
||||
}
|
||||
if (typeof watchQuery === 'function') {
|
||||
return watchQuery.apply(instance, [to.query, from.query])
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (startLoader && this.$loading.start && !this.$loading.manual) {
|
||||
this.$loading.start()
|
||||
}
|
||||
}
|
||||
// Call next()
|
||||
next()
|
||||
} catch (error) {
|
||||
const err = error || {}
|
||||
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
|
||||
const message = err.message || ''
|
||||
|
||||
// Handle chunk loading errors
|
||||
// This may be due to a new deployment or a network problem
|
||||
if (/^Loading( CSS)? chunk (\d)+ failed\./.test(message)) {
|
||||
window.location.reload(true /* skip cache */)
|
||||
return // prevent error page blinking for user
|
||||
}
|
||||
|
||||
this.error({ statusCode, message })
|
||||
this.$nuxt.$emit('routeChanged', to, from, err)
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
function applySSRData (Component, ssrData) {
|
||||
if (NUXT.serverRendered && ssrData) {
|
||||
applyAsyncData(Component, ssrData)
|
||||
}
|
||||
|
||||
Component._Ctor = Component
|
||||
return Component
|
||||
}
|
||||
|
||||
// Get matched components
|
||||
function resolveComponents (route) {
|
||||
return flatMapComponents(route, async (Component, _, match, key, index) => {
|
||||
// If component is not resolved yet, resolve it
|
||||
if (typeof Component === 'function' && !Component.options) {
|
||||
Component = await Component()
|
||||
}
|
||||
// Sanitize it and save it
|
||||
const _Component = applySSRData(sanitizeComponent(Component), NUXT.data ? NUXT.data[index] : null)
|
||||
match.components[key] = _Component
|
||||
return _Component
|
||||
})
|
||||
}
|
||||
|
||||
function callMiddleware (Components, context, layout, renderState) {
|
||||
let midd = ["route"]
|
||||
let unknownMiddleware = false
|
||||
|
||||
// If layout is undefined, only call global middleware
|
||||
if (typeof layout !== 'undefined') {
|
||||
midd = [] // Exclude global middleware if layout defined (already called before)
|
||||
layout = sanitizeComponent(layout)
|
||||
if (layout.options.middleware) {
|
||||
midd = midd.concat(layout.options.middleware)
|
||||
}
|
||||
Components.forEach((Component) => {
|
||||
if (Component.options.middleware) {
|
||||
midd = midd.concat(Component.options.middleware)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
midd = midd.map((name) => {
|
||||
if (typeof name === 'function') {
|
||||
return name
|
||||
}
|
||||
if (typeof middleware[name] !== 'function') {
|
||||
unknownMiddleware = true
|
||||
this.error({ statusCode: 500, message: 'Unknown middleware ' + name })
|
||||
}
|
||||
return middleware[name]
|
||||
})
|
||||
|
||||
if (unknownMiddleware) {
|
||||
return
|
||||
}
|
||||
return middlewareSeries(midd, context, renderState)
|
||||
}
|
||||
|
||||
async function render (to, from, next, renderState) {
|
||||
if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) {
|
||||
return next()
|
||||
}
|
||||
// Handle first render on SPA mode
|
||||
let spaFallback = false
|
||||
if (to === from) {
|
||||
_lastPaths = []
|
||||
spaFallback = true
|
||||
} else {
|
||||
const fromMatches = []
|
||||
_lastPaths = getMatchedComponents(from, fromMatches).map((Component, i) => {
|
||||
return compile(from.matched[fromMatches[i]].path)(from.params)
|
||||
})
|
||||
}
|
||||
|
||||
// nextCalled is true when redirected
|
||||
let nextCalled = false
|
||||
const _next = (path) => {
|
||||
if (from.path === path.path && this.$loading.finish) {
|
||||
this.$loading.finish()
|
||||
}
|
||||
|
||||
if (from.path !== path.path && this.$loading.pause) {
|
||||
this.$loading.pause()
|
||||
}
|
||||
|
||||
if (nextCalled) {
|
||||
return
|
||||
}
|
||||
|
||||
nextCalled = true
|
||||
next(path)
|
||||
}
|
||||
|
||||
// Update context
|
||||
await setContext(app, {
|
||||
route: to,
|
||||
from,
|
||||
error: (err) => {
|
||||
if (renderState.aborted) {
|
||||
return
|
||||
}
|
||||
app.nuxt.error.call(this, err)
|
||||
},
|
||||
next: _next.bind(this)
|
||||
})
|
||||
this._dateLastError = app.nuxt.dateErr
|
||||
this._hadError = Boolean(app.nuxt.err)
|
||||
|
||||
// Get route's matched components
|
||||
const matches = []
|
||||
const Components = getMatchedComponents(to, matches)
|
||||
|
||||
// If no Components matched, generate 404
|
||||
if (!Components.length) {
|
||||
// Default layout
|
||||
await callMiddleware.call(this, Components, app.context, undefined, renderState)
|
||||
if (nextCalled) {
|
||||
return
|
||||
}
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Load layout for error page
|
||||
const errorLayout = (NuxtError.options || NuxtError).layout
|
||||
const layout = await this.loadLayout(
|
||||
typeof errorLayout === 'function'
|
||||
? errorLayout.call(NuxtError, app.context)
|
||||
: errorLayout
|
||||
)
|
||||
|
||||
await callMiddleware.call(this, Components, app.context, layout, renderState)
|
||||
if (nextCalled) {
|
||||
return
|
||||
}
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Show error page
|
||||
app.context.error({ statusCode: 404, message: 'This page could not be found' })
|
||||
return next()
|
||||
}
|
||||
|
||||
// Update ._data and other properties if hot reloaded
|
||||
Components.forEach((Component) => {
|
||||
if (Component._Ctor && Component._Ctor.options) {
|
||||
Component.options.asyncData = Component._Ctor.options.asyncData
|
||||
Component.options.fetch = Component._Ctor.options.fetch
|
||||
}
|
||||
})
|
||||
|
||||
// Apply transitions
|
||||
this.setTransitions(mapTransitions(Components, to, from))
|
||||
|
||||
try {
|
||||
// Call middleware
|
||||
await callMiddleware.call(this, Components, app.context, undefined, renderState)
|
||||
if (nextCalled) {
|
||||
return
|
||||
}
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
if (app.context._errored) {
|
||||
return next()
|
||||
}
|
||||
|
||||
// Set layout
|
||||
let layout = Components[0].options.layout
|
||||
if (typeof layout === 'function') {
|
||||
layout = layout(app.context)
|
||||
}
|
||||
layout = await this.loadLayout(layout)
|
||||
|
||||
// Call middleware for layout
|
||||
await callMiddleware.call(this, Components, app.context, layout, renderState)
|
||||
if (nextCalled) {
|
||||
return
|
||||
}
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
if (app.context._errored) {
|
||||
return next()
|
||||
}
|
||||
|
||||
// Call .validate()
|
||||
let isValid = true
|
||||
try {
|
||||
for (const Component of Components) {
|
||||
if (typeof Component.options.validate !== 'function') {
|
||||
continue
|
||||
}
|
||||
|
||||
isValid = await Component.options.validate(app.context)
|
||||
|
||||
if (!isValid) {
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (validationError) {
|
||||
// ...If .validate() threw an error
|
||||
this.error({
|
||||
statusCode: validationError.statusCode || '500',
|
||||
message: validationError.message
|
||||
})
|
||||
return next()
|
||||
}
|
||||
|
||||
// ...If .validate() returned false
|
||||
if (!isValid) {
|
||||
this.error({ statusCode: 404, message: 'This page could not be found' })
|
||||
return next()
|
||||
}
|
||||
|
||||
let instances
|
||||
// Call asyncData & fetch hooks on components matched by the route.
|
||||
await Promise.all(Components.map(async (Component, i) => {
|
||||
// Check if only children route changed
|
||||
Component._path = compile(to.matched[matches[i]].path)(to.params)
|
||||
Component._dataRefresh = false
|
||||
const childPathChanged = Component._path !== _lastPaths[i]
|
||||
// Refresh component (call asyncData & fetch) when:
|
||||
// Route path changed part includes current component
|
||||
// Or route param changed part includes current component and watchParam is not `false`
|
||||
// Or route query is changed and watchQuery returns `true`
|
||||
if (this._routeChanged && childPathChanged) {
|
||||
Component._dataRefresh = true
|
||||
} else if (this._paramChanged && childPathChanged) {
|
||||
const watchParam = Component.options.watchParam
|
||||
Component._dataRefresh = watchParam !== false
|
||||
} else if (this._queryChanged) {
|
||||
const watchQuery = Component.options.watchQuery
|
||||
if (watchQuery === true) {
|
||||
Component._dataRefresh = true
|
||||
} else if (Array.isArray(watchQuery)) {
|
||||
Component._dataRefresh = watchQuery.some(key => this._diffQuery[key])
|
||||
} else if (typeof watchQuery === 'function') {
|
||||
if (!instances) {
|
||||
instances = getMatchedComponentsInstances(to)
|
||||
}
|
||||
Component._dataRefresh = watchQuery.apply(instances[i], [to.query, from.query])
|
||||
}
|
||||
}
|
||||
if (!this._hadError && this._isMounted && !Component._dataRefresh) {
|
||||
return
|
||||
}
|
||||
|
||||
const promises = []
|
||||
|
||||
const hasAsyncData = (
|
||||
Component.options.asyncData &&
|
||||
typeof Component.options.asyncData === 'function'
|
||||
)
|
||||
|
||||
const hasFetch = Boolean(Component.options.fetch) && Component.options.fetch.length
|
||||
|
||||
const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45
|
||||
|
||||
// Call asyncData(context)
|
||||
if (hasAsyncData) {
|
||||
const promise = promisify(Component.options.asyncData, app.context)
|
||||
|
||||
promise.then((asyncDataResult) => {
|
||||
applyAsyncData(Component, asyncDataResult)
|
||||
|
||||
if (this.$loading.increase) {
|
||||
this.$loading.increase(loadingIncrease)
|
||||
}
|
||||
})
|
||||
promises.push(promise)
|
||||
}
|
||||
|
||||
// Check disabled page loading
|
||||
this.$loading.manual = Component.options.loading === false
|
||||
|
||||
// Call fetch(context)
|
||||
if (hasFetch) {
|
||||
let p = Component.options.fetch(app.context)
|
||||
if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) {
|
||||
p = Promise.resolve(p)
|
||||
}
|
||||
p.then((fetchResult) => {
|
||||
if (this.$loading.increase) {
|
||||
this.$loading.increase(loadingIncrease)
|
||||
}
|
||||
})
|
||||
promises.push(p)
|
||||
}
|
||||
|
||||
return Promise.all(promises)
|
||||
}))
|
||||
|
||||
// If not redirected
|
||||
if (!nextCalled) {
|
||||
if (this.$loading.finish && !this.$loading.manual) {
|
||||
this.$loading.finish()
|
||||
}
|
||||
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
next()
|
||||
}
|
||||
} catch (err) {
|
||||
if (renderState.aborted) {
|
||||
next(false)
|
||||
return
|
||||
}
|
||||
const error = err || {}
|
||||
if (error.message === 'ERR_REDIRECT') {
|
||||
return this.$nuxt.$emit('routeChanged', to, from, error)
|
||||
}
|
||||
_lastPaths = []
|
||||
|
||||
globalHandleError(error)
|
||||
|
||||
// Load error layout
|
||||
let layout = (NuxtError.options || NuxtError).layout
|
||||
if (typeof layout === 'function') {
|
||||
layout = layout(app.context)
|
||||
}
|
||||
await this.loadLayout(layout)
|
||||
|
||||
this.error(error)
|
||||
this.$nuxt.$emit('routeChanged', to, from, error)
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
// Fix components format in matched, it's due to code-splitting of vue-router
|
||||
function normalizeComponents (to, ___) {
|
||||
flatMapComponents(to, (Component, _, match, key) => {
|
||||
if (typeof Component === 'object' && !Component.options) {
|
||||
// Updated via vue-router resolveAsyncComponents()
|
||||
Component = Vue.extend(Component)
|
||||
Component._Ctor = Component
|
||||
match.components[key] = Component
|
||||
}
|
||||
return Component
|
||||
})
|
||||
}
|
||||
|
||||
function setLayoutForNextPage (to) {
|
||||
// Set layout
|
||||
let hasError = Boolean(this.$options.nuxt.err)
|
||||
if (this._hadError && this._dateLastError === this.$options.nuxt.dateErr) {
|
||||
hasError = false
|
||||
}
|
||||
let layout = hasError
|
||||
? (NuxtError.options || NuxtError).layout
|
||||
: to.matched[0].components.default.options.layout
|
||||
|
||||
if (typeof layout === 'function') {
|
||||
layout = layout(app.context)
|
||||
}
|
||||
|
||||
this.setLayout(layout)
|
||||
}
|
||||
|
||||
function checkForErrors (app) {
|
||||
// Hide error component if no error
|
||||
if (app._hadError && app._dateLastError === app.$options.nuxt.dateErr) {
|
||||
app.error()
|
||||
}
|
||||
}
|
||||
|
||||
// When navigating on a different route but the same component is used, Vue.js
|
||||
// Will not update the instance data, so we have to update $data ourselves
|
||||
function fixPrepatch (to, ___) {
|
||||
if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) {
|
||||
return
|
||||
}
|
||||
|
||||
const instances = getMatchedComponentsInstances(to)
|
||||
const Components = getMatchedComponents(to)
|
||||
|
||||
let triggerScroll = false
|
||||
|
||||
Vue.nextTick(() => {
|
||||
instances.forEach((instance, i) => {
|
||||
if (!instance || instance._isDestroyed) {
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
instance.constructor._dataRefresh &&
|
||||
Components[i] === instance.constructor &&
|
||||
instance.$vnode.data.keepAlive !== true &&
|
||||
typeof instance.constructor.options.data === 'function'
|
||||
) {
|
||||
const newData = instance.constructor.options.data.call(instance)
|
||||
for (const key in newData) {
|
||||
Vue.set(instance.$data, key, newData[key])
|
||||
}
|
||||
|
||||
triggerScroll = true
|
||||
}
|
||||
})
|
||||
|
||||
if (triggerScroll) {
|
||||
// Ensure to trigger scroll event after calling scrollBehavior
|
||||
window.$nuxt.$nextTick(() => {
|
||||
window.$nuxt.$emit('triggerScroll')
|
||||
})
|
||||
}
|
||||
|
||||
checkForErrors(this)
|
||||
})
|
||||
}
|
||||
|
||||
function nuxtReady (_app) {
|
||||
window.onNuxtReadyCbs.forEach((cb) => {
|
||||
if (typeof cb === 'function') {
|
||||
cb(_app)
|
||||
}
|
||||
})
|
||||
// Special JSDOM
|
||||
if (typeof window._onNuxtLoaded === 'function') {
|
||||
window._onNuxtLoaded(_app)
|
||||
}
|
||||
// Add router hooks
|
||||
router.afterEach((to, from) => {
|
||||
// Wait for fixPrepatch + $data updates
|
||||
Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from))
|
||||
})
|
||||
}
|
||||
|
||||
async function mountApp (__app) {
|
||||
// Set global variables
|
||||
app = __app.app
|
||||
router = __app.router
|
||||
store = __app.store
|
||||
|
||||
// Create Vue instance
|
||||
const _app = new Vue(app)
|
||||
|
||||
// Load layout
|
||||
const layout = NUXT.layout || 'default'
|
||||
await _app.loadLayout(layout)
|
||||
_app.setLayout(layout)
|
||||
|
||||
// Mounts Vue app to DOM element
|
||||
const mount = () => {
|
||||
_app.$mount('#__nuxt')
|
||||
|
||||
// Add afterEach router hooks
|
||||
router.afterEach(normalizeComponents)
|
||||
|
||||
router.afterEach(setLayoutForNextPage.bind(_app))
|
||||
|
||||
router.afterEach(fixPrepatch.bind(_app))
|
||||
|
||||
// Listen for first Vue update
|
||||
Vue.nextTick(() => {
|
||||
// Call window.{{globals.readyCallback}} callbacks
|
||||
nuxtReady(_app)
|
||||
})
|
||||
}
|
||||
|
||||
// Resolve route components
|
||||
const Components = await Promise.all(resolveComponents(app.context.route))
|
||||
|
||||
// Enable transitions
|
||||
_app.setTransitions = _app.$options.nuxt.setTransitions.bind(_app)
|
||||
if (Components.length) {
|
||||
_app.setTransitions(mapTransitions(Components, router.currentRoute))
|
||||
_lastPaths = router.currentRoute.matched.map(route => compile(route.path)(router.currentRoute.params))
|
||||
}
|
||||
|
||||
// Initialize error handler
|
||||
_app.$loading = {} // To avoid error while _app.$nuxt does not exist
|
||||
if (NUXT.error) {
|
||||
_app.error(NUXT.error)
|
||||
}
|
||||
|
||||
// Add beforeEach router hooks
|
||||
router.beforeEach(loadAsyncComponents.bind(_app))
|
||||
|
||||
// Each new invocation of render() aborts previous invocation
|
||||
let renderState = null
|
||||
const boundRender = render.bind(_app)
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (renderState) {
|
||||
renderState.aborted = true
|
||||
}
|
||||
renderState = { aborted: false }
|
||||
boundRender(to, from, next, renderState)
|
||||
})
|
||||
|
||||
// Fix in static: remove trailing slash to force hydration
|
||||
// Full static, if server-rendered: hydrate, to allow custom redirect to generated page
|
||||
|
||||
// Fix in static: remove trailing slash to force hydration
|
||||
if (NUXT.serverRendered && isSamePath(NUXT.routePath, _app.context.route.path)) {
|
||||
return mount()
|
||||
}
|
||||
|
||||
// First render on client-side
|
||||
const clientFirstMount = () => {
|
||||
normalizeComponents(router.currentRoute, router.currentRoute)
|
||||
setLayoutForNextPage.call(_app, router.currentRoute)
|
||||
checkForErrors(_app)
|
||||
// Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render
|
||||
mount()
|
||||
}
|
||||
|
||||
// fix: force next tick to avoid having same timestamp when an error happen on spa fallback
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
render.call(_app, router.currentRoute, router.currentRoute, (path) => {
|
||||
// If not redirected
|
||||
if (!path) {
|
||||
clientFirstMount()
|
||||
return
|
||||
}
|
||||
|
||||
// Add a one-time afterEach hook to
|
||||
// mount the app wait for redirect and route gets resolved
|
||||
const unregisterHook = router.afterEach((to, from) => {
|
||||
unregisterHook()
|
||||
clientFirstMount()
|
||||
})
|
||||
|
||||
// Push the path and let route to be resolved
|
||||
router.push(path, undefined, (err) => {
|
||||
if (err) {
|
||||
errorHandler(err)
|
||||
}
|
||||
})
|
||||
},
|
||||
{ aborted: false })
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
export const ActivityArea = () => import('../..\\components\\activity-area.vue' /* webpackChunkName: "components/activity-area" */).then(c => wrapFunctional(c.default || c))
|
||||
export const AdItem = () => import('../..\\components\\ad-item.vue' /* webpackChunkName: "components/ad-item" */).then(c => wrapFunctional(c.default || c))
|
||||
export const AddressAdd = () => import('../..\\components\\address-add.vue' /* webpackChunkName: "components/address-add" */).then(c => wrapFunctional(c.default || c))
|
||||
export const AddressList = () => import('../..\\components\\address-list.vue' /* webpackChunkName: "components/address-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const AfterSalesList = () => import('../..\\components\\after-sales-list.vue' /* webpackChunkName: "components/after-sales-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const CommentList = () => import('../..\\components\\comment-list.vue' /* webpackChunkName: "components/comment-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const CountDown = () => import('../..\\components\\count-down.vue' /* webpackChunkName: "components/count-down" */).then(c => wrapFunctional(c.default || c))
|
||||
export const CouponsList = () => import('../..\\components\\coupons-list.vue' /* webpackChunkName: "components/coupons-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const DeliverSearch = () => import('../..\\components\\deliver-search.vue' /* webpackChunkName: "components/deliver-search" */).then(c => wrapFunctional(c.default || c))
|
||||
export const EvaluationList = () => import('../..\\components\\evaluation-list.vue' /* webpackChunkName: "components/evaluation-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const GoodsList = () => import('../..\\components\\goods-list.vue' /* webpackChunkName: "components/goods-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const HomeSeckill = () => import('../..\\components\\home-seckill.vue' /* webpackChunkName: "components/home-seckill" */).then(c => wrapFunctional(c.default || c))
|
||||
export const InputExpress = () => import('../..\\components\\input-Express.vue' /* webpackChunkName: "components/input-express" */).then(c => wrapFunctional(c.default || c))
|
||||
export const NullData = () => import('../..\\components\\null-data.vue' /* webpackChunkName: "components/null-data" */).then(c => wrapFunctional(c.default || c))
|
||||
export const NumberBox = () => import('../..\\components\\number-box.vue' /* webpackChunkName: "components/number-box" */).then(c => wrapFunctional(c.default || c))
|
||||
export const OrderList = () => import('../..\\components\\order-list.vue' /* webpackChunkName: "components/order-list" */).then(c => wrapFunctional(c.default || c))
|
||||
export const PriceFormate = () => import('../..\\components\\price-formate.vue' /* webpackChunkName: "components/price-formate" */).then(c => wrapFunctional(c.default || c))
|
||||
export const ShopItem = () => import('../..\\components\\shop-item.vue' /* webpackChunkName: "components/shop-item" */).then(c => wrapFunctional(c.default || c))
|
||||
export const Upload = () => import('../..\\components\\upload.vue' /* webpackChunkName: "components/upload" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutAslideNav = () => import('../..\\components\\layout\\aslide-nav.vue' /* webpackChunkName: "components/layout-aslide-nav" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutCategory = () => import('../..\\components\\layout\\category.vue' /* webpackChunkName: "components/layout-category" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutFloatNav = () => import('../..\\components\\layout\\float-nav.vue' /* webpackChunkName: "components/layout-float-nav" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutFooter = () => import('../..\\components\\layout\\footer.vue' /* webpackChunkName: "components/layout-footer" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutHeader = () => import('../..\\components\\layout\\header.vue' /* webpackChunkName: "components/layout-header" */).then(c => wrapFunctional(c.default || c))
|
||||
export const LayoutMainNav = () => import('../..\\components\\layout\\main-nav.vue' /* webpackChunkName: "components/layout-main-nav" */).then(c => wrapFunctional(c.default || c))
|
||||
|
||||
// nuxt/nuxt.js#8607
|
||||
function wrapFunctional(options) {
|
||||
if (!options || !options.functional) {
|
||||
return options
|
||||
}
|
||||
|
||||
const propKeys = Array.isArray(options.props) ? options.props : Object.keys(options.props || {})
|
||||
|
||||
return {
|
||||
render(h) {
|
||||
const attrs = {}
|
||||
const props = {}
|
||||
|
||||
for (const key in this.$attrs) {
|
||||
if (propKeys.includes(key)) {
|
||||
props[key] = this.$attrs[key]
|
||||
} else {
|
||||
attrs[key] = this.$attrs[key]
|
||||
}
|
||||
}
|
||||
|
||||
return h(options, {
|
||||
on: this.$listeners,
|
||||
attrs,
|
||||
props,
|
||||
scopedSlots: this.$scopedSlots,
|
||||
}, this.$slots.default)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
export default {
|
||||
name: 'NuxtChild',
|
||||
functional: true,
|
||||
props: {
|
||||
nuxtChildKey: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
keepAlive: Boolean,
|
||||
keepAliveProps: {
|
||||
type: Object,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
render (_, { parent, data, props }) {
|
||||
const h = parent.$createElement
|
||||
|
||||
data.nuxtChild = true
|
||||
const _parent = parent
|
||||
const transitions = parent.$nuxt.nuxt.transitions
|
||||
const defaultTransition = parent.$nuxt.nuxt.defaultTransition
|
||||
|
||||
let depth = 0
|
||||
while (parent) {
|
||||
if (parent.$vnode && parent.$vnode.data.nuxtChild) {
|
||||
depth++
|
||||
}
|
||||
parent = parent.$parent
|
||||
}
|
||||
data.nuxtChildDepth = depth
|
||||
const transition = transitions[depth] || defaultTransition
|
||||
const transitionProps = {}
|
||||
transitionsKeys.forEach((key) => {
|
||||
if (typeof transition[key] !== 'undefined') {
|
||||
transitionProps[key] = transition[key]
|
||||
}
|
||||
})
|
||||
|
||||
const listeners = {}
|
||||
listenersKeys.forEach((key) => {
|
||||
if (typeof transition[key] === 'function') {
|
||||
listeners[key] = transition[key].bind(_parent)
|
||||
}
|
||||
})
|
||||
if (process.client) {
|
||||
// Add triggerScroll event on beforeEnter (fix #1376)
|
||||
const beforeEnter = listeners.beforeEnter
|
||||
listeners.beforeEnter = (el) => {
|
||||
// Ensure to trigger scroll event after calling scrollBehavior
|
||||
window.$nuxt.$nextTick(() => {
|
||||
window.$nuxt.$emit('triggerScroll')
|
||||
})
|
||||
if (beforeEnter) {
|
||||
return beforeEnter.call(_parent, el)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// make sure that leave is called asynchronous (fix #5703)
|
||||
if (transition.css === false) {
|
||||
const leave = listeners.leave
|
||||
|
||||
// only add leave listener when user didnt provide one
|
||||
// or when it misses the done argument
|
||||
if (!leave || leave.length < 2) {
|
||||
listeners.leave = (el, done) => {
|
||||
if (leave) {
|
||||
leave.call(_parent, el)
|
||||
}
|
||||
|
||||
_parent.$nextTick(done)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let routerView = h('routerView', data)
|
||||
|
||||
if (props.keepAlive) {
|
||||
routerView = h('keep-alive', { props: props.keepAliveProps }, [routerView])
|
||||
}
|
||||
|
||||
return h('transition', {
|
||||
props: transitionProps,
|
||||
on: listeners
|
||||
}, [routerView])
|
||||
}
|
||||
}
|
||||
|
||||
const transitionsKeys = [
|
||||
'name',
|
||||
'mode',
|
||||
'appear',
|
||||
'css',
|
||||
'type',
|
||||
'duration',
|
||||
'enterClass',
|
||||
'leaveClass',
|
||||
'appearClass',
|
||||
'enterActiveClass',
|
||||
'enterActiveClass',
|
||||
'leaveActiveClass',
|
||||
'appearActiveClass',
|
||||
'enterToClass',
|
||||
'leaveToClass',
|
||||
'appearToClass'
|
||||
]
|
||||
|
||||
const listenersKeys = [
|
||||
'beforeEnter',
|
||||
'enter',
|
||||
'afterEnter',
|
||||
'enterCancelled',
|
||||
'beforeLeave',
|
||||
'leave',
|
||||
'afterLeave',
|
||||
'leaveCancelled',
|
||||
'beforeAppear',
|
||||
'appear',
|
||||
'afterAppear',
|
||||
'appearCancelled'
|
||||
]
|
|
@ -0,0 +1,96 @@
|
|||
<template>
|
||||
<div class="__nuxt-error-page">
|
||||
<div class="error">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="90" height="90" fill="#DBE1EC" viewBox="0 0 48 48">
|
||||
<path d="M22 30h4v4h-4zm0-16h4v12h-4zm1.99-10C12.94 4 4 12.95 4 24s8.94 20 19.99 20S44 35.05 44 24 35.04 4 23.99 4zM24 40c-8.84 0-16-7.16-16-16S15.16 8 24 8s16 7.16 16 16-7.16 16-16 16z" />
|
||||
</svg>
|
||||
|
||||
<div class="title">{{ message }}</div>
|
||||
<p v-if="statusCode === 404" class="description">
|
||||
<a v-if="typeof $route === 'undefined'" class="error-link" href="/"></a>
|
||||
<NuxtLink v-else class="error-link" to="/">Back to the home page</NuxtLink>
|
||||
</p>
|
||||
|
||||
<div class="logo">
|
||||
<a href="https://nuxtjs.org" target="_blank" rel="noopener">Nuxt</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'NuxtError',
|
||||
props: {
|
||||
error: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
statusCode () {
|
||||
return (this.error && this.error.statusCode) || 500
|
||||
},
|
||||
message () {
|
||||
return this.error.message || 'Error'
|
||||
}
|
||||
},
|
||||
head () {
|
||||
return {
|
||||
title: this.message,
|
||||
meta: [
|
||||
{
|
||||
name: 'viewport',
|
||||
content: 'width=device-width,initial-scale=1.0,minimum-scale=1.0'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.__nuxt-error-page {
|
||||
padding: 1rem;
|
||||
background: #F7F8FB;
|
||||
color: #47494E;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
font-family: sans-serif;
|
||||
font-weight: 100 !important;
|
||||
-ms-text-size-adjust: 100%;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
.__nuxt-error-page .error {
|
||||
max-width: 450px;
|
||||
}
|
||||
.__nuxt-error-page .title {
|
||||
font-size: 1.5rem;
|
||||
margin-top: 15px;
|
||||
color: #47494E;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.__nuxt-error-page .description {
|
||||
color: #7F828B;
|
||||
line-height: 21px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.__nuxt-error-page a {
|
||||
color: #7F828B !important;
|
||||
text-decoration: none;
|
||||
}
|
||||
.__nuxt-error-page .logo {
|
||||
position: fixed;
|
||||
left: 12px;
|
||||
bottom: 12px;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,98 @@
|
|||
import Vue from 'vue'
|
||||
|
||||
const requestIdleCallback = window.requestIdleCallback ||
|
||||
function (cb) {
|
||||
const start = Date.now()
|
||||
return setTimeout(function () {
|
||||
cb({
|
||||
didTimeout: false,
|
||||
timeRemaining: () => Math.max(0, 50 - (Date.now() - start))
|
||||
})
|
||||
}, 1)
|
||||
}
|
||||
|
||||
const cancelIdleCallback = window.cancelIdleCallback || function (id) {
|
||||
clearTimeout(id)
|
||||
}
|
||||
|
||||
const observer = window.IntersectionObserver && new window.IntersectionObserver((entries) => {
|
||||
entries.forEach(({ intersectionRatio, target: link }) => {
|
||||
if (intersectionRatio <= 0 || !link.__prefetch) {
|
||||
return
|
||||
}
|
||||
link.__prefetch()
|
||||
})
|
||||
})
|
||||
|
||||
export default {
|
||||
name: 'NuxtLink',
|
||||
extends: Vue.component('RouterLink'),
|
||||
props: {
|
||||
prefetch: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
noPrefetch: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
if (this.prefetch && !this.noPrefetch) {
|
||||
this.handleId = requestIdleCallback(this.observe, { timeout: 2e3 })
|
||||
}
|
||||
},
|
||||
beforeDestroy () {
|
||||
cancelIdleCallback(this.handleId)
|
||||
|
||||
if (this.__observed) {
|
||||
observer.unobserve(this.$el)
|
||||
delete this.$el.__prefetch
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
observe () {
|
||||
// If no IntersectionObserver, avoid prefetching
|
||||
if (!observer) {
|
||||
return
|
||||
}
|
||||
// Add to observer
|
||||
if (this.shouldPrefetch()) {
|
||||
this.$el.__prefetch = this.prefetchLink.bind(this)
|
||||
observer.observe(this.$el)
|
||||
this.__observed = true
|
||||
}
|
||||
},
|
||||
shouldPrefetch () {
|
||||
return this.getPrefetchComponents().length > 0
|
||||
},
|
||||
canPrefetch () {
|
||||
const conn = navigator.connection
|
||||
const hasBadConnection = this.$nuxt.isOffline || (conn && ((conn.effectiveType || '').includes('2g') || conn.saveData))
|
||||
|
||||
return !hasBadConnection
|
||||
},
|
||||
getPrefetchComponents () {
|
||||
const ref = this.$router.resolve(this.to, this.$route, this.append)
|
||||
const Components = ref.resolved.matched.map(r => r.components.default)
|
||||
|
||||
return Components.filter(Component => typeof Component === 'function' && !Component.options && !Component.__prefetched)
|
||||
},
|
||||
prefetchLink () {
|
||||
if (!this.canPrefetch()) {
|
||||
return
|
||||
}
|
||||
// Stop observing this link (in case of internet connection changes)
|
||||
observer.unobserve(this.$el)
|
||||
const Components = this.getPrefetchComponents()
|
||||
|
||||
for (const Component of Components) {
|
||||
const componentOrPromise = Component()
|
||||
if (componentOrPromise instanceof Promise) {
|
||||
componentOrPromise.catch(() => {})
|
||||
}
|
||||
Component.__prefetched = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
import Vue from 'vue'
|
||||
|
||||
export default {
|
||||
name: 'NuxtLink',
|
||||
extends: Vue.component('RouterLink'),
|
||||
props: {
|
||||
prefetch: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
noPrefetch: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
<script>
|
||||
export default {
|
||||
name: 'NuxtLoading',
|
||||
data () {
|
||||
return {
|
||||
percent: 0,
|
||||
show: false,
|
||||
canSucceed: true,
|
||||
reversed: false,
|
||||
skipTimerCount: 0,
|
||||
rtl: false,
|
||||
throttle: 200,
|
||||
duration: 5000,
|
||||
continuous: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
left () {
|
||||
if (!this.continuous && !this.rtl) {
|
||||
return false
|
||||
}
|
||||
return this.rtl
|
||||
? (this.reversed ? '0px' : 'auto')
|
||||
: (!this.reversed ? '0px' : 'auto')
|
||||
}
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.clear()
|
||||
},
|
||||
methods: {
|
||||
clear () {
|
||||
clearInterval(this._timer)
|
||||
clearTimeout(this._throttle)
|
||||
clearTimeout(this._hide)
|
||||
this._timer = null
|
||||
},
|
||||
start () {
|
||||
this.clear()
|
||||
this.percent = 0
|
||||
this.reversed = false
|
||||
this.skipTimerCount = 0
|
||||
this.canSucceed = true
|
||||
|
||||
if (this.throttle) {
|
||||
this._throttle = setTimeout(() => this.startTimer(), this.throttle)
|
||||
} else {
|
||||
this.startTimer()
|
||||
}
|
||||
return this
|
||||
},
|
||||
set (num) {
|
||||
this.show = true
|
||||
this.canSucceed = true
|
||||
this.percent = Math.min(100, Math.max(0, Math.floor(num)))
|
||||
return this
|
||||
},
|
||||
get () {
|
||||
return this.percent
|
||||
},
|
||||
increase (num) {
|
||||
this.percent = Math.min(100, Math.floor(this.percent + num))
|
||||
return this
|
||||
},
|
||||
decrease (num) {
|
||||
this.percent = Math.max(0, Math.floor(this.percent - num))
|
||||
return this
|
||||
},
|
||||
pause () {
|
||||
clearInterval(this._timer)
|
||||
return this
|
||||
},
|
||||
resume () {
|
||||
this.startTimer()
|
||||
return this
|
||||
},
|
||||
finish () {
|
||||
this.percent = this.reversed ? 0 : 100
|
||||
this.hide()
|
||||
return this
|
||||
},
|
||||
hide () {
|
||||
this.clear()
|
||||
this._hide = setTimeout(() => {
|
||||
this.show = false
|
||||
this.$nextTick(() => {
|
||||
this.percent = 0
|
||||
this.reversed = false
|
||||
})
|
||||
}, 500)
|
||||
return this
|
||||
},
|
||||
fail (error) {
|
||||
this.canSucceed = false
|
||||
return this
|
||||
},
|
||||
startTimer () {
|
||||
if (!this.show) {
|
||||
this.show = true
|
||||
}
|
||||
if (typeof this._cut === 'undefined') {
|
||||
this._cut = 10000 / Math.floor(this.duration)
|
||||
}
|
||||
|
||||
this._timer = setInterval(() => {
|
||||
/**
|
||||
* When reversing direction skip one timers
|
||||
* so 0, 100 are displayed for two iterations
|
||||
* also disable css width transitioning
|
||||
* which otherwise interferes and shows
|
||||
* a jojo effect
|
||||
*/
|
||||
if (this.skipTimerCount > 0) {
|
||||
this.skipTimerCount--
|
||||
return
|
||||
}
|
||||
|
||||
if (this.reversed) {
|
||||
this.decrease(this._cut)
|
||||
} else {
|
||||
this.increase(this._cut)
|
||||
}
|
||||
|
||||
if (this.continuous) {
|
||||
if (this.percent >= 100) {
|
||||
this.skipTimerCount = 1
|
||||
|
||||
this.reversed = !this.reversed
|
||||
} else if (this.percent <= 0) {
|
||||
this.skipTimerCount = 1
|
||||
|
||||
this.reversed = !this.reversed
|
||||
}
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
},
|
||||
render (h) {
|
||||
let el = h(false)
|
||||
if (this.show) {
|
||||
el = h('div', {
|
||||
staticClass: 'nuxt-progress',
|
||||
class: {
|
||||
'nuxt-progress-notransition': this.skipTimerCount > 0,
|
||||
'nuxt-progress-failed': !this.canSucceed
|
||||
},
|
||||
style: {
|
||||
width: this.percent + '%',
|
||||
left: this.left
|
||||
}
|
||||
})
|
||||
}
|
||||
return el
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.nuxt-progress {
|
||||
position: fixed;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
right: 0px;
|
||||
height: 2px;
|
||||
width: 0%;
|
||||
opacity: 1;
|
||||
transition: width 0.1s, opacity 0.4s;
|
||||
background-color: black;
|
||||
z-index: 999999;
|
||||
}
|
||||
|
||||
.nuxt-progress.nuxt-progress-notransition {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.nuxt-progress-failed {
|
||||
background-color: red;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,101 @@
|
|||
import Vue from 'vue'
|
||||
import { compile } from '../utils'
|
||||
|
||||
import NuxtError from '../..\\layouts\\error.vue'
|
||||
|
||||
import NuxtChild from './nuxt-child'
|
||||
|
||||
export default {
|
||||
name: 'Nuxt',
|
||||
components: {
|
||||
NuxtChild,
|
||||
NuxtError
|
||||
},
|
||||
props: {
|
||||
nuxtChildKey: {
|
||||
type: String,
|
||||
default: undefined
|
||||
},
|
||||
keepAlive: Boolean,
|
||||
keepAliveProps: {
|
||||
type: Object,
|
||||
default: undefined
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
default: 'default'
|
||||
}
|
||||
},
|
||||
errorCaptured (error) {
|
||||
// if we receive and error while showing the NuxtError component
|
||||
// capture the error and force an immediate update so we re-render
|
||||
// without the NuxtError component
|
||||
if (this.displayingNuxtError) {
|
||||
this.errorFromNuxtError = error
|
||||
this.$forceUpdate()
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
routerViewKey () {
|
||||
// If nuxtChildKey prop is given or current route has children
|
||||
if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) {
|
||||
return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params)
|
||||
}
|
||||
|
||||
const [matchedRoute] = this.$route.matched
|
||||
|
||||
if (!matchedRoute) {
|
||||
return this.$route.path
|
||||
}
|
||||
|
||||
const Component = matchedRoute.components.default
|
||||
|
||||
if (Component && Component.options) {
|
||||
const { options } = Component
|
||||
|
||||
if (options.key) {
|
||||
return (typeof options.key === 'function' ? options.key(this.$route) : options.key)
|
||||
}
|
||||
}
|
||||
|
||||
const strict = /\/$/.test(matchedRoute.path)
|
||||
return strict ? this.$route.path : this.$route.path.replace(/\/$/, '')
|
||||
}
|
||||
},
|
||||
beforeCreate () {
|
||||
Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt)
|
||||
},
|
||||
render (h) {
|
||||
// if there is no error
|
||||
if (!this.nuxt.err) {
|
||||
// Directly return nuxt child
|
||||
return h('NuxtChild', {
|
||||
key: this.routerViewKey,
|
||||
props: this.$props
|
||||
})
|
||||
}
|
||||
|
||||
// if an error occurred within NuxtError show a simple
|
||||
// error message instead to prevent looping
|
||||
if (this.errorFromNuxtError) {
|
||||
this.$nextTick(() => (this.errorFromNuxtError = false))
|
||||
|
||||
return h('div', {}, [
|
||||
h('h2', 'An error occurred while showing the error page'),
|
||||
h('p', 'Unfortunately an error occurred and while showing the error page another error occurred'),
|
||||
h('p', `Error details: ${this.errorFromNuxtError.toString()}`),
|
||||
h('nuxt-link', { props: { to: '/' } }, 'Go back to home')
|
||||
])
|
||||
}
|
||||
|
||||
// track if we are showing the NuxtError component
|
||||
this.displayingNuxtError = true
|
||||
this.$nextTick(() => (this.displayingNuxtError = false))
|
||||
|
||||
return h(NuxtError, {
|
||||
props: {
|
||||
error: this.nuxt.err
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import Vue from 'vue'
|
||||
import * as components from './index'
|
||||
|
||||
for (const name in components) {
|
||||
Vue.component(name, components[name])
|
||||
Vue.component('Lazy' + name, components[name])
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
# Discovered Components
|
||||
|
||||
This is an auto-generated list of components discovered by [nuxt/components](https://github.com/nuxt/components).
|
||||
|
||||
You can directly use them in pages and other components without the need to import them.
|
||||
|
||||
**Tip:** If a component is conditionally rendered with `v-if` and is big, it is better to use `Lazy` or `lazy-` prefix to lazy load.
|
||||
|
||||
- `<ActivityArea>` | `<activity-area>` (components/activity-area.vue)
|
||||
- `<AdItem>` | `<ad-item>` (components/ad-item.vue)
|
||||
- `<AddressAdd>` | `<address-add>` (components/address-add.vue)
|
||||
- `<AddressList>` | `<address-list>` (components/address-list.vue)
|
||||
- `<AfterSalesList>` | `<after-sales-list>` (components/after-sales-list.vue)
|
||||
- `<CommentList>` | `<comment-list>` (components/comment-list.vue)
|
||||
- `<CountDown>` | `<count-down>` (components/count-down.vue)
|
||||
- `<CouponsList>` | `<coupons-list>` (components/coupons-list.vue)
|
||||
- `<DeliverSearch>` | `<deliver-search>` (components/deliver-search.vue)
|
||||
- `<EvaluationList>` | `<evaluation-list>` (components/evaluation-list.vue)
|
||||
- `<GoodsList>` | `<goods-list>` (components/goods-list.vue)
|
||||
- `<HomeSeckill>` | `<home-seckill>` (components/home-seckill.vue)
|
||||
- `<InputExpress>` | `<input-express>` (components/input-Express.vue)
|
||||
- `<NullData>` | `<null-data>` (components/null-data.vue)
|
||||
- `<NumberBox>` | `<number-box>` (components/number-box.vue)
|
||||
- `<OrderList>` | `<order-list>` (components/order-list.vue)
|
||||
- `<PriceFormate>` | `<price-formate>` (components/price-formate.vue)
|
||||
- `<ShopItem>` | `<shop-item>` (components/shop-item.vue)
|
||||
- `<Upload>` | `<upload>` (components/upload.vue)
|
||||
- `<LayoutAslideNav>` | `<layout-aslide-nav>` (components/layout/aslide-nav.vue)
|
||||
- `<LayoutCategory>` | `<layout-category>` (components/layout/category.vue)
|
||||
- `<LayoutFloatNav>` | `<layout-float-nav>` (components/layout/float-nav.vue)
|
||||
- `<LayoutFooter>` | `<layout-footer>` (components/layout/footer.vue)
|
||||
- `<LayoutHeader>` | `<layout-header>` (components/layout/header.vue)
|
||||
- `<LayoutMainNav>` | `<layout-main-nav>` (components/layout/main-nav.vue)
|
|
@ -0,0 +1,9 @@
|
|||
import cookieUniversal from 'cookie-universal'
|
||||
|
||||
export default ({ req, res }, inject) => {
|
||||
const options = {
|
||||
"alias": "cookies",
|
||||
"parseJSON": true
|
||||
}
|
||||
inject(options.alias, cookieUniversal(req, res, options.parseJSON))
|
||||
}
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 136 KiB |
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 170 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |