Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
// TODO 监听3000端口,便于执行test
import express from "express"
import { createSSRApp } from 'vue'
import { renderToString } from 'vue/server-renderer'



const instance = express()

instance.get('/', (req, res) => {

const app = createSSRApp({
data: () => ({ contentStr: 'Vue SSR Example' }),
template: `<div>{{ contentStr }}</div>`
})

renderToString(app).then((html) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Vue SSR Example</title>
</head>
<body>
<div id="app">${html}</div>
</body>
</html>
`)
console.log(html)
})
})

instance.listen(3000, () => {
console.log('The listen port is 3000');
})
Loading