App.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import Vue from 'vue'
  2. import NuxtLoading from './components/nuxt-loading.vue'
  3. import '../assets/css/common.css'
  4. import _6f6c098b from '../layouts/default.vue'
  5. const layouts = { "_default": _6f6c098b }
  6. export default {
  7. head: {"title":"程序员客栈","meta":[{"charset":"utf-8"},{"name":"viewport","content":"width=device-width, initial-scale=1"},{"name":"baidu-site-verification","content":"7IbkIN9Kwp"},{"http-equiv":"X-UA-Compatible","content":"IE=edge,chrome=1"},{"name":"robots","content":"noindex,follow"},{"name":"description","content":"proginn ssr project"}],"link":[{"rel":"icon","type":"image\u002Fx-icon","href":"\u002Ffavicon.ico"}],"style":[],"script":[]},
  8. render(h, props) {
  9. const loadingEl = h('nuxt-loading', { ref: 'loading' })
  10. const layoutEl = h(this.layout || 'nuxt')
  11. const templateEl = h('div', {
  12. domProps: {
  13. id: '__layout'
  14. },
  15. key: this.layoutName
  16. }, [ layoutEl ])
  17. const transitionEl = h('transition', {
  18. props: {
  19. name: 'layout',
  20. mode: 'out-in'
  21. },
  22. on: {
  23. beforeEnter(el) {
  24. // Ensure to trigger scroll event after calling scrollBehavior
  25. window.$nuxt.$nextTick(() => {
  26. window.$nuxt.$emit('triggerScroll')
  27. })
  28. }
  29. }
  30. }, [ templateEl ])
  31. return h('div', {
  32. domProps: {
  33. id: '__nuxt'
  34. }
  35. }, [
  36. loadingEl,
  37. transitionEl
  38. ])
  39. },
  40. data: () => ({
  41. layout: null,
  42. layoutName: ''
  43. }),
  44. beforeCreate() {
  45. Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt)
  46. },
  47. created() {
  48. // Add this.$nuxt in child instances
  49. Vue.prototype.$nuxt = this
  50. // add to window so we can listen when ready
  51. if (typeof window !== 'undefined') {
  52. window.$nuxt = this
  53. }
  54. // Add $nuxt.error()
  55. this.error = this.nuxt.error
  56. },
  57. mounted() {
  58. this.$loading = this.$refs.loading
  59. },
  60. watch: {
  61. 'nuxt.err': 'errorChanged'
  62. },
  63. methods: {
  64. errorChanged() {
  65. if (this.nuxt.err && this.$loading) {
  66. if (this.$loading.fail) this.$loading.fail()
  67. if (this.$loading.finish) this.$loading.finish()
  68. }
  69. },
  70. setLayout(layout) {
  71. if(layout && typeof layout !== 'string') throw new Error('[nuxt] Avoid using non-string value as layout property.')
  72. if (!layout || !layouts['_' + layout]) {
  73. layout = 'default'
  74. }
  75. this.layoutName = layout
  76. this.layout = layouts['_' + layout]
  77. return this.layout
  78. },
  79. loadLayout(layout) {
  80. if (!layout || !layouts['_' + layout]) {
  81. layout = 'default'
  82. }
  83. return Promise.resolve(layouts['_' + layout])
  84. }
  85. },
  86. components: {
  87. NuxtLoading
  88. }
  89. }