From eb559e6ff4f619e5238b2f42bd3537c8208eccb9 Mon Sep 17 00:00:00 2001
From: xh12 <1960939421@qq.com>
Date: Sun, 4 Sep 2022 10:55:36 +0000
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app.js | 11 +++++++++++
client.js | 3 +++
server.js | 29 +++++++++++++++++++++++++++++
3 files changed, 43 insertions(+)
create mode 100644 app.js
create mode 100644 client.js
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..51cc397
--- /dev/null
+++ b/app.js
@@ -0,0 +1,11 @@
+import { createSSRApp } from 'vue'
+
+export function createApp() {
+ return createSSRApp({
+ data: () => ({
+ content: 'Vue SSR Example'
+ }),
+ template: `
{{ content }}
`
+ })
+}
+
diff --git a/client.js b/client.js
new file mode 100644
index 0000000..92aa98c
--- /dev/null
+++ b/client.js
@@ -0,0 +1,3 @@
+import { createApp } from "./app.js";
+
+createApp().mount('#app')
\ No newline at end of file
diff --git a/server.js b/server.js
index a5cefe0..43a3cf0 100644
--- a/server.js
+++ b/server.js
@@ -1 +1,30 @@
// TODO 监听3000端口,便于执行test
+import express from 'express'
+import { createApp } from './app.js'
+import { renderToString } from 'vue/server-renderer'
+
+const server = express()
+
+server.get('/', (req, res) => {
+ const app = createApp()
+
+ renderToString(app).then((html) => {
+ res.send(`
+
+
+
+ Vue SSR Example
+
+
+
+ ${html}
+
+
+ `)
+ })
+})
+
+server.use(express.static('.'))
+server.listen(3000, () => {
+ console.log('服务启动了')
+})
\ No newline at end of file