HTML is undefined
in-there opened this issue · 0 comments
in-there commented
var express = require('express');
var router = express.Router();
var renderer = require('vue-server-renderer').createRenderer({
template : require('fs').readFileSync('views/index.html','utf-8')
});
var Vue = require('../public/javascripts/vue.js');
/* GET home page. */
router.get('/', function (req, res, next) {
const app = new Vue({
data:{
url:req.url
},
template:`<div>{{url}}</div>`
})
const context = {
title:'test'
}
renderer.renderToString(app,context,(err,html)=>{
// console.log(html)
if(err){
res.status(500).end(err)
return
}
res.end(html)
})
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
</head>
<body>
<!--vue-ssr-outlet-->
<h1>{{ title }}</h1>
</body>
</html>
construction
结构
HTML sometimes is undefined
- use express
- when i firstly use these code , it's undefined
- but after I restart the vscode ,it's ok
- the reason I don' know
HTML有时候是undefined
- 使用express框架
- 当我第一次使用时,它就是undefined
- 但是我重启了vscode编辑器后,它成功渲染了出来
- 我不知道这到底是什么原因