CoreUI使用故障排查:官方模板无法正常运行求助
解决CoreUI无法正常运行的问题
你的代码里有两个关键问题导致CoreUI无法正常加载:
- CoreUI资源链接错误:你使用的CSS和JS链接包含
browse路径,这是unpkg的文件浏览页面地址,不是可直接引入的资源文件地址,浏览器无法正确加载样式和脚本。 - jQuery协议问题:使用了
http协议的jQuery链接,在HTTPS环境下会被浏览器拦截,导致依赖加载失败。
修正后的代码如下:
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- CoreUI CSS(移除了browse路径) --> <link rel="stylesheet" href="https://unpkg.com/@coreui/coreui@2.1.16/dist/css/coreui.min.css"> <title>Hello, world!</title> </head> <body class="app"> <h1>Hello, world!</h1> <div class="container"> <div class="row"> <div class="col"> 1/2 </div> <div class="col"> 1/2 </div> </div> <div class="row"> <div class="col"> 1/3 </div> <div class="col"> 1/3 </div> <div class="col"> 1/3 </div> </div> </div> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, Bootstrap, then CoreUI --> <!-- jQuery改为https协议 --> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> <!-- CoreUI JS移除了browse路径 --> <script src="https://unpkg.com/@coreui/coreui@2.1.16/dist/js/coreui.min.js"></script> </body> </html>
修改说明:
- 所有CoreUI的资源链接去掉了
browse/部分,让浏览器能直接加载对应的CSS和JS文件。 - 将jQuery的链接协议从
http改为https,避免混合内容拦截问题。
替换代码后,CoreUI的样式和功能就能正常生效了。
内容的提问来源于stack exchange,提问作者EazyP
相关产品推荐
相关产品推荐

