【发布时间】:2021-01-11 06:25:36
【问题描述】:
我正在尝试将 axios 与 pug 模板一起使用,但遇到了问题。 这是我的代码: base.pug
doctype html
html
head
block head
meta(charset='UTF-8')
meta(name='viewport' content='width=device-width, initial-scale=1.0')
link(rel='stylesheet' href='/css/style.css')
link(rel='shortcut icon' type='image/png' href='/img/favicon.png')
link(rel='stylesheet' href='https://fonts.googleapis.com/css?family=Lato:300,300i,700')
title Natours | #{title}
body
// HEADER
include _header
// CONTENT
block content
h1 This is a placeholder heading
// FOOTER
include _footer
script(src='https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js')
script(src='/js/login.js')
在 login.js 中
const login = async (email, password) => {
try {
const res = await axios({
method: 'POST',
url: 'http:127.0.0.1:3000/api/v1/login',
data: {
email,
password
}
});
console.log(res);
} catch (err) {
console.log(err);
}
};
document.querySelector('.form').addEventListener('submit', e => {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
login(email, password);
});
但每次我尝试提交表单时,我都会在 console.log 中收到此错误 " 拒绝加载脚本“https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js”,因为它违反了以下内容安全策略指令:“script-src 'self'” .请注意,'script-src-elem' 没有明确设置,因此 'script-src' 用作后备。 "
【问题讨论】:
-
我看到有人也在做 Udemy 的 Natours nodejs 课程;)