一、今晚遇到一个问题,就是不能直接在 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{
{ message }}
// js/test.js src="js/vue.min.js"> new Vue({ el: '#chen_test_id1', data: { message: 'Hello Vue.js!' } })