1
<?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。

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

4

1 回答 1

0

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

于 2018-05-21T03:24:20.610 回答