React框架如何在dva中添加jquery

时间:2017-07-19 07:53:55

标签: jquery reactjs webpack

React-dva,webpack的包也是打包的,这样用户就无法看到webpack配置了。如何加入jquery?

2 个答案:

答案 0 :(得分:0)

它"困难"与react.js一起使用jQuery。 jQuery通过修改真实DOM来工作,而react.js则修改虚拟DOM。同步两个库之间对DOM所做的更改很困难。

答案 1 :(得分:0)

1,在package.json中配置jQuery。您可以在npm https://www.npmjs.com/package/jquery(这是来自jquery的分支)或GitHub

上找到依赖项
import $ from 'jquery';

2,将jQuery导入到您想要使用的位置

const aDomNode = $("#DomNodeId");

3,使用它

function Occurrences(const Substring, Text: string): Integer;
    var
      offset: Integer;
    begin
      Result := 0;
      offset := PosEx(Substring, Text, 1);

      while offset <> 0 do
      begin
        inc(Result);
        offset := PosEx(Substring, Text, offset + Length(Substring));
        // If the string isn't found any more, offset becomes 0, but
        // you still add a new string to the memo...
        memo1.Lines.Add(Copy(Text, offset, Length(Substring)+2));
      end;
    end;

4,提示:使用React时不要使用jQuery。

相关问题