At.js icon indicating copy to clipboard operation
At.js copied to clipboard

用npm安装at.js,再require进项目,webpack会报一大堆的错误

Open simplecooler opened this issue 9 years ago • 7 comments

simplecooler avatar Jun 29 '16 07:06 simplecooler

应该是 npm install 的时候自动分析并安装了 jq 依赖,你手动删除 at.js 下面的 node_modules 试一下看还会不会报错。

anchengjian avatar Jun 30 '16 03:06 anchengjian

删除了就报找不到node_modules/at.js/node_modules/jquery/lib/node-jquery.js

simplecooler avatar Jun 30 '16 03:06 simplecooler

这个项目是依赖 jquery 的,你在外层自己的项目中装一个 jquery ,或者进 at.js 目录下面,重新装一个 jquery。这样子就不得报错了

anchengjian avatar Jun 30 '16 06:06 anchengjian

项目中外层有jquery,但用的是v2.2.2,可能是这个原因,at.js是基于v1.x.x的,然后就不对了

simplecooler avatar Jun 30 '16 07:06 simplecooler

不是的,这个不影响。作者自己的例子都是2.2的。对了,我知道了,你删除了后要重启一下 webpack 啊,不然 webpack 的缓存依然依赖你删除前的模块

anchengjian avatar Jun 30 '16 07:06 anchengjian

[1027] 如何在webpack/react环境中引入at.js 要在react中加jquery本就别扭 更何况加的是jquery插件 一时无法摆脱jq 只能注意解决摩擦之处

class EditorForm extends Component {
  componentDidUpdate () {
    const { members } = this.props
    $('#editor').atwho({ at: '@', data: members })
  }
}
// wrong
import $ from 'jquery'
import 'jquery.caret'
import 'at.js/dist/css/jquery.atwho.css'
import 'at.js'

// correct
import $ from 'jquery'
import 'jquery.caret'
import '../fork/jquery.atwho.css' // custom styles
import '../fork/jquery.atwho.js' // some fix
// ../fork/jquery.atwho.js
App.prototype.onKeydown = function(e) {
  // ...
    case KEY_CODE.SPACE:
      // ...
      if (view.highlighted()) {
        e.preventDefault();

+        // fix: conflict with react EditorForm onKeyDown
+        // hitting enter also submits form
+        e.stopPropagation(); // added

        view.choose(e);
      } else {
        view.hide(e);
      }
}
// ...
Controller.prototype.lookUp = function(e) {
    var query, wait;

+    // fix: composite `@`+ Chinese character
+    // TypeError: Cannot read property 'which' of undefined
+    // at EditableController.catchQuery (jquery.atwho.js?:727:12)
+    // at EditableController.Controller.lookUp
+    if (!e) return; // added

fritx avatar Oct 27 '16 14:10 fritx

@simplecooler shasahi sfsfds jfsdpo @simplecooler fsfsfsf

shashiranjansingh avatar Jul 20 '17 12:07 shashiranjansingh