vuepress引入外部組件後build報錯window is not defined

解決方法

不要全局註冊組件,在單頁的mounted裏動態引入

<template>
  <component v-if="dynamicComponent" :is="dynamicComponent"></component>
</template>
<script>
export default {
  data() {
    return {
      dynamicComponent: null
    }
  },
  mounted () {
    import('./lib-that-access-window-on-import').then(module => {
      this.dynamicComponent = module.default
    })
  }
}
</script>

參考鏈接:

https://vuepress.vuejs.org/zh/guide/using-vue.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章