【问题标题】:V8Js::compileString():14026: ReferenceError: window is not definedV8Js::compileString():14026: ReferenceError: window is not defined
【发布时间】:2018-10-28 13:56:53
【问题描述】:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;

class AppController extends Controller
{
  private function render() {
   $renderer_source = File::get(base_path('node_modules/vue-server-renderer/basic.js'));
   $app_source = File::get(public_path('js/entry-server.js'));

   $v8 = new \V8Js();

   ob_start();

   $v8->executeString('var process = { env: { VUE_ENV: "server", NODE_ENV: "production" }}; this.global = { process: process };');
   $v8->executeString($renderer_source);
   $v8->executeString($app_source);

   return ob_get_clean();
 }

 public function get() {
   $ssr = $this->render();
   return view('app', ['ssr' => $ssr]);
 }
}

我关注了https://dzone.com/articles/server-side-rendering-with-laravel-amp-vuejs-25这个页面并且 安装了 V8Js。 但是 $v8->executeString($app_source);犯一个错误 V8Js::compileString():14026: ReferenceError: window is not defined.

我不知道如何处理这个错误..

【问题讨论】:

  • 服务器端渲染时没有窗口对象,请检查您的代码关于窗口对象的使用位置

标签: laravel vue.js v8js


【解决方案1】:

问题是 bootstrap.js 使用窗口对象。谢了!

【讨论】:

    猜你喜欢
    • 2018-12-02
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2020-04-04
    • 2021-12-29
    相关资源
    最近更新 更多