search

Home  >  Q&A  >  body text

Questions about loading css and js

Teacher, 10-2 Community front-end page_2 In this course, you used "/static/css/bootstrap.css" to load the style. Why did I get an error when I loaded it according to this path? The 'bootstrap.css' and 'js' files cannot be referenced correctly. Is the path defined in which configuration file, but I don't see you using constants such as "__PUBLIC__" or "__STATIC__". Baidu has tried many methods but has not been able to solve it. Please answer. Thank you very much! !

iUnicorniUnicorn2016 days ago1257

reply all(5)I'll reply

  • Single

    Single2019-05-09 16:55:11

    The path is definitely wrong. Your constant definition path is spliced ​​into a relative path that is not the real path. Open F12 in Google Chrome to see the path of the console static file

    reply
    0
  • iUnicorn

    Hello, thanks for the reply. The reference code I wrote in phpstrom is as follows: The path is correct, and PS does not prompt an error. However, the console in the browser will prompt an error message as follows: Failed to load resource: the server responded with a status of 404 (Not Found) /public/static/Bootstrap_4.1.1/dist/css/bootstrap.css:1 So I tried to use "constant" after Baidu, but it prompted that the path was wrong! !

    iUnicorn · 2019-05-09 17:37:17
    iUnicorn

    All right! ! Solved, the path can only be written according to Teacher Zhu’s writing method, as follows: href="/static/css/bootstrap.css" src="/static/js/jquery-3.2.1.min.js" I can't find the reason for the time being. I can only attribute it to some settings of ThinkPHP that I haven't learned yet. I'll talk about it later.

    iUnicorn · 2019-05-09 21:21:03
    Single

    If it is tp5, there is a place to set template constants. You can check the manual yourself.

    Single · 2019-05-10 08:36:42
    Single

    In the configuration

    Single · 2019-05-10 08:37:05
  • Cancelreply