V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
WEBUG
V2EX  ›  Vue.js

问下 vue cli 怎么实现 script 回调函数,函数在 main.ts 里面写提示找不到

  •  
  •   WEBUG · Aug 9, 2020 · 2016 views
    This topic created in 2098 days ago, the information mentioned may be changed or developed.
    想要调用百度之类的联想词,原来用的 vue2.0 可以用 jsonp 简单实现,现在 3.0 没发用了,就想自己实现一个 jsonp,结果回调函数写在 main.ts 里面会报错函数找不到,直接把函数写在 index.html 里面确实能调到,但是不太方便。有没有其他方法
    4 replies    2020-08-11 11:32:30 +08:00
    noe132
        1
    noe132  
       Aug 9, 2020
    cosnt jsonpCallBack = () => {}


    window.xxxxxjsonpcallback = jsonpCallBack
    WEBUG
        2
    WEBUG  
    OP
       Aug 9, 2020
    @noe132 刚发出帖子就找到解决办法了,和你这个一样,原来 ts 里面直接写 winsow.xxx 会报错,所以开始一只没有测试这个写法,现在可以了
    WEBUG
        3
    WEBUG  
    OP
       Aug 9, 2020
    window.xxx 上面回复打错了
    MrTreasure
        4
    MrTreasure  
       Aug 11, 2020
    ```typescritp
    declaer interface Window {
    jsonpcallback: () => data
    }
    ```
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3298 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:30 · PVG 21:30 · LAX 06:30 · JFK 09:30
    ♥ Do have faith in what you're doing.