mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
examples: Use process.server instead of isServer
This commit is contained in:
parent
262bffc35d
commit
23e1c3fd06
@ -7,8 +7,8 @@ module.exports = {
|
|||||||
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
|
app: 'app.[chunkhash].js' // default: nuxt.bundle.[chunkhash].js
|
||||||
},
|
},
|
||||||
vendor: ['lodash'],
|
vendor: ['lodash'],
|
||||||
extend (config, { dev }) {
|
extend (config, { isDev }) {
|
||||||
if (dev) {
|
if (isDev) {
|
||||||
config.devtool = 'eval-source-map'
|
config.devtool = 'eval-source-map'
|
||||||
}
|
}
|
||||||
const urlLoader = config.module.rules.find((loader) => loader.loader === 'url-loader')
|
const urlLoader = config.module.rules.find((loader) => loader.loader === 'url-loader')
|
||||||
|
@ -3,7 +3,7 @@ import VueI18n from 'vue-i18n'
|
|||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
export default ({ app, isClient, store }) => {
|
export default ({ app, store }) => {
|
||||||
// Set i18n instance on app
|
// Set i18n instance on app
|
||||||
// This way we can use it in middleware and pages asyncData/fetch
|
// This way we can use it in middleware and pages asyncData/fetch
|
||||||
app.i18n = new VueI18n({
|
app.i18n = new VueI18n({
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
asyncData ({ isServer }) {
|
asyncData () {
|
||||||
return {
|
return {
|
||||||
name: (isServer ? 'server' : 'client')
|
name: (process.server ? 'server' : 'client')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ export const getCookies = (str) => {
|
|||||||
** Executed by ~/.nuxt/index.js with context given
|
** Executed by ~/.nuxt/index.js with context given
|
||||||
** This method can be asynchronous
|
** This method can be asynchronous
|
||||||
*/
|
*/
|
||||||
export default ({ isServer, req }, inject) => {
|
export default ({ req }, inject) => {
|
||||||
// Inject `cookies` key
|
// Inject `cookies` key
|
||||||
// -> app.$cookies
|
// -> app.$cookies
|
||||||
// -> this.$cookies in vue components
|
// -> this.$cookies in vue components
|
||||||
// -> this.$cookies in store actions/mutations
|
// -> this.$cookies in store actions/mutations
|
||||||
inject('cookies', new Vue({
|
inject('cookies', new Vue({
|
||||||
data: () => ({
|
data: () => ({
|
||||||
cookies: getCookies(isServer ? req.headers.cookie : document.cookie)
|
cookies: getCookies(process.server ? req.headers.cookie : document.cookie)
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
set(...args) {
|
set(...args) {
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
asyncData ({ req, isServer }) {
|
asyncData () {
|
||||||
return {
|
return {
|
||||||
name: req ? 'server' : 'client'
|
name: process.server ? 'server' : 'client'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user