vue ssr 組件使用document 、window對象 加載問題


解決方法:

            <template>
              <div>
                <Loading></Loading>
              </div>
            </template>

            <script type="text/babel">
              export default {
                data(){
                  return {
                        }
                },
                beforeMount() {
                  // 只會在瀏覽器執行  
                  this.$options.components.Loading = () =>import('vue-loading');
                },
                mounted(){
                }
              }
            </script>

使用beforeMount 函數去加載組件,這樣組件在服務端就不會渲染,組件還可以配合v-if去控制組件的渲染

參考文章


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM