Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 由于MIME类型,我的html出现错误_Javascript_Html_Node.js_Vue.js - Fatal编程技术网

Javascript 由于MIME类型,我的html出现错误

Javascript 由于MIME类型,我的html出现错误,javascript,html,node.js,vue.js,Javascript,Html,Node.js,Vue.js,所以我的项目有一个问题,我开发了一个NodeJS服务器,现在我想显示一个html文件,其中包含一个Vue脚本,该脚本通过另一个js文件中编写的另一个方法加载数据 但当我尝试在浏览器上加载html文件时,出现以下错误:拒绝从“”执行脚本,因为它的MIME类型(“text/html”)不可执行,并且启用了严格的MIME类型检查 以下是我的html代码: <!DOCTYPE html> <html lang="fr"> <head> <

所以我的项目有一个问题,我开发了一个NodeJS服务器,现在我想显示一个html文件,其中包含一个Vue脚本,该脚本通过另一个js文件中编写的另一个方法加载数据

但当我尝试在浏览器上加载html文件时,出现以下错误:拒绝从“”执行脚本,因为它的MIME类型(“text/html”)不可执行,并且启用了严格的MIME类型检查

以下是我的html代码:

<!DOCTYPE html>
<html lang="fr">

    <head>
        <meta charset="utf-8">
        <meta content="X-Content-Type-Options: nosniff">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

       <script src="/src/verbatims.js" type="application/javascript"></script>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>


        <title>My project</title>
    </head>

    <body>
        <div id="data">
            Le nombre de requête est de  : {{ request }}<br>
            <button v-on:click="change">Change value</button>
            <button v-on:click="stop">Arrêter</button>
        </div>

        <script>
            let app = new Vue({
                el:'#data',
                data: {
                    request: "toto",
                    ite: 0
                },
                methods: {
                    change: function() {
                        changeNbRequest()
                    },
                    stop: function() {
                        clearInterval()
                    }
                }
            });

            changeNbRequest = function() {
                var timer = setInterval(function() {
                    let verbatim = new Verbatims().list()[ite];
                }, 5000);
            }
        </script>
    </body>
</html>
浏览器永远不会发送URL中包含
。/
的请求

它将在发送之前使路径正常化

您需要将路由指定为
/src/verbatims.js



您还应该考虑使用静态文件处理中间件,而不是手动为每个中间件创建路由。

我们无法解释为什么您的web服务器声称
/src/verbatims.js
是基于您提供的信息的HTML文档。它可能是404 HTML错误页-尝试
而不是
/src
-另外,您可能希望在加载任何其他js之前加载vue.jsfile@Quentin你需要什么?@mplungjan我试着用这种方法,但我有同样的方法error@MissKnacki-足够详细的信息来确定服务器如何决定它将做出什么响应。好的,非常感谢,我已经对路径进行了正常化,它可以正常工作!我已经尝试使用静态文件处理中间件,但它不起作用:/
const express = require('express')
const RouterVerbatim = require('./routerVerbatim')
const fs = require('fs')

class Server {

  constructor() {
    this.app = express()

    this.app.get('/', function (req, res) {
      res.send('Hello World')
    })

    this.app.get('/index', function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/html'});
      fs.readFile(__dirname + '/View/index.html', function (err,data) {
          res.end(data);
      });
    })

    this.app.get('../src/verbatims.js', function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/javascript'});
      fs.readFile('../src/verbatims.js', function (err,data) {
          res.end(data);
      });
    })

    this.app.use('/verbatims', new RouterVerbatim().router)
  }

  start() {
    this.app.listen(8080, function() {
      console.log('Exemple app listening on port 8080!')
    })
  }

}
module.exports = Server;
'../src/verbatims.js'