app.js
var http = require("http");
var fs = require('fs');
var url = require('url'); http.createServer(function(request, response) {
// 解析请求,包括文件名
var pathname = url.parse(request.url).pathname;
// 输出请求的文件名
console.log("Request for " + pathname + " received.");
// 从文件系统中读取请求的文件内容
fs.readFile(pathname.substr(), function(err, data) {
if (err) {
console.log(err);
// HTTP 状态码: 404 : NOT FOUND
// Content Type: text/plain
response.writeHead(, { 'Content-Type': 'text/html' });
} else {
// HTTP 状态码: 200 : OK
// Content Type: text/plain
response.writeHead(, { 'Content-Type': 'text/html' }); // 响应文件内容
response.write(data.toString());
}
// 发送响应数据
response.end(); });
}).listen(); console.log('Server running at http://127.0.0.1:8888/index.html');
index.html
<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
</head> <body>
<!--这是我们的View-->
<div id="app">
<p>{{ message }}</p>
<input type="text" v-model="message" />
<h1>Hello, Vue.js!</h1>
<h1 v-if="yes">Yes!</h1>
<h1 v-if="no">No!</h1>
<h1 v-if="age >= 25">Age: {{ age }}</h1>
<h1 v-if="name.indexOf('jack') >= 0">Name: {{ name }}</h1>
</div>
</body>
<script src="https://unpkg.com/vue@2.5.17/dist/vue.js"></script>
<script>
// 这是我们的Model
var exampleData = {
message: 'Hello World!',
yes: true,
no: false,
age: ,
name: 'keepfooljack' } // 创建一个 Vue 实例或 "ViewModel"
// 它连接 View 与 Model
new Vue({
el: '#app',
data: exampleData
})
</script> </html>