我正在尝试在我的node.js应用程序中运行vue.js代码,但是当我在终端中使用node index.js
运行我的代码时,我在浏览器中得到了{{ name }}而不是{{约翰}}
HTML:
<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="/style.css">
<title>Document</title>
</head>
<body>
<div id="app">
<h1>
{{name}}
</h1>
</div>
</body>
</html>
JavaScript:
var Vue = require('vue');
var express = require('express');
var app = express();
var http = require('http');
var server = http.Server(app);
server.listen(3000,function () {
console.log('starting the server');
});
app.use(express.static(__dirname));
app.get('/',function (req,res) {
res.sendFile(__dirname + +'/index.html');
})
new Vue({
el:'#app',
data:{
name:'john'
},
})
任何帮助:)
注意: 我正在使用从 npm 安装的 vue 模块
最佳答案
Vue 是一个客户端框架,需要在您所服务的网页上运行,而不是在为其提供服务的 Node 客户端上运行。
如果您尝试为 Vue 进行服务器端渲染,您需要遵循该指南。
关于javascript - vue.js 变量无法与 Node.js 一起使用 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50005914/