morning
V2EX  ›  Vue.js

请问在 vue-cli 引入一个 js 文件(微信)并使用,最简单的方法是什么?

  •  
  •   morning · Jun 17, 2016 · 4737 views
    This topic created in 3627 days ago, the information mentioned may be changed or developed.

    按照 这里的解决办法 https://segmentfault.com/q/1010000005169531

    1. 在 index.html 引入了 js 文件.
    2. webpack.base.conf.js添加:externals: { 'wx': 'jWeixin' }
    3. import wx from 'wx' 的时候 提示 can not resoilve module 'wx'

    请问在 vue-cli 引入一个 js 文件(微信)并使用,最简单的方法是什么?还有第 2 步这里 每次都要自己进 js 文件找函数名吗?

    Supplement 1  ·  Jun 29, 2016

    这边忘记写了,比较好用的三个方式.

    • 方法一: index.html 全局引入js,使用时 window. ,同理还有window.alert('233')
    • 方法二: 去npmjs.com 里找到要用的模块,安装引入即可. const wx = require('weixin-js-sdk') (使用时记得把全局的js注释掉)
    • 方法三: 使用 https://github.com/webpack/script-loader
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2832 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 14:54 · PVG 22:54 · LAX 07:54 · JFK 10:54
    ♥ Do have faith in what you're doing.