V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
mkfsmkfs
V2EX  ›  问与答

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

  •  1
     
  •   mkfsmkfs · Sep 5, 2018 · 1844 views
    This topic created in 2803 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
        1
    acthtml  
       Sep 5, 2018   ❤️ 1
    require('./example.js')即可。
    mkfsmkfs
        2
    mkfsmkfs  
    OP
       Sep 5, 2018
    @acthtml 不只是 js,还有其他文件,比如 jpg,mp3 呢?
    jy02534655
        3
    jy02534655  
       Sep 5, 2018   ❤️ 1
    楼主平时都是用绝对路径么?
    qiayue
        4
    qiayue  
    PRO
       Sep 5, 2018   ❤️ 1
    相对路径了解一下
    maichael
        5
    maichael  
       Sep 5, 2018   ❤️ 1
    相对路径了解一下。
    mkfsmkfs
        6
    mkfsmkfs  
    OP
       Sep 5, 2018
    @mkfsmkfs 好吧果然是错误的
    路径加
    ./
    即可
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5436 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 07:08 · PVG 15:08 · LAX 00:08 · JFK 03:08
    ♥ Do have faith in what you're doing.