一、今晚遇到一个问题,就是不能直接在 html 直接调用 js 代码的问题

二、会出现如下错误:

    Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-    vKuX0yKlIAX3ZzZ9/PIUq7x1z425uZLu4glsP+4fqXM='), or a nonce ('nonce-...') is required to enable inline execution.

三、解决方法,就是将 js 代码写成单独的文件,然后包含进去即可。

    # index.html
    <!DOCTYPE html>
    <html>
      <head>
        <script src="js/vue.min.js"> </script>
      </head>
  
      <body>
        <div >
          <p>{{ message }}</p>
        </div>
        <script src="js/test.js"> </script>
      </body>

    </html>
    // js/test.js
    src="js/vue.min.js">
    new Vue({
      el: '#chen_test_id1',
      data: {
        message: 'Hello Vue.js!'
      }
    })

相关文章:

  • 2022-12-23
  • 2021-09-04
  • 2021-05-26
  • 2021-05-06
  • 2021-06-16
  • 2022-12-23
猜你喜欢
  • 2021-12-27
  • 2021-05-28
  • 2022-12-23
  • 2021-05-31
  • 2021-08-14
相关资源
相似解决方案