zoukankan      html  css  js  c++  java
  • node day2 vue read html

    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(1), function(err, data) {
            if (err) {
                console.log(err);
                // HTTP 状态码: 404 : NOT FOUND
                // Content Type: text/plain
                response.writeHead(404, { 'Content-Type': 'text/html' });
            } else {
                // HTTP 状态码: 200 : OK
                // Content Type: text/plain
                response.writeHead(200, { 'Content-Type': 'text/html' });
     
                // 响应文件内容
                response.write(data.toString());
            }
            //  发送响应数据
            response.end();
     
        });
    }).listen(8888);
     
    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: 28,
            name: 'keepfooljack'
     
        }
     
        // 创建一个 Vue 实例或 "ViewModel"
        // 它连接 View 与 Model
        new Vue({
            el: '#app',
            data: exampleData
        })
    </script>
     
    </html>
  • 相关阅读:
    MT【319】分段递推数列
    MT【318】分式不等式双代换
    Centos7环境变量
    VI快捷键
    Centos7 开机自动运行命令
    Centos7 编辑本地DNS解析配置文件
    Centos7修改主机名
    xadmin 自定义过滤器选项
    Centos7网卡配置文件
    Centos7 挂载
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/10406414.html
Copyright © 2011-2022 走看看