mkfsmkfs
V2EX  ›  问与答

我想通过前端 js 脚本获取自身目录的方式解决依赖问题,这种想法是不是错了,正解是什么?

  •  1
     
  •   mkfsmkfs · Sep 5, 2018 · 2306 views
    This topic created in 2980 days ago, the information mentioned may be changed or developed.

    比如

    test.js 检测自身在 /aaaa/bbbb/text.js
    就会加载 /aaaa/bbbb/example.js

    test.js 检测自身在 /xxxx/text.js
    就会加载 /xxxx/example.js

    6 replies  •  2018-09-05 10:11:37 +08:00
    acthtml
    acthtml
    Sep 5, 2018❤️1
    1
    require('./example.js')即可。
    mkfsmkfs
    mkfsmkfs
    OP
    Sep 5, 2018
    2
    @acthtml 不只是 js,还有其他文件,比如 jpg,mp3 呢?
    jy02534655
    jy02534655
    Sep 5, 2018❤️1
    3
    楼主平时都是用绝对路径么?
    qiayue
    qiayue
    Sep 5, 2018❤️1
    4
    相对路径了解一下
    maichael
    maichael
    Sep 5, 2018❤️1
    5
    相对路径了解一下。
    mkfsmkfs
    mkfsmkfs
    OP
    Sep 5, 2018
    6
    @mkfsmkfs 好吧果然是错误的
    路径加
    ./
    即可
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1368 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:10 · PVG 06:10 · LAX 14:10 · JFK 17:10
    ♥ Do have faith in what you're doing.