0

我有一个由 HTML 设计师设计的 html。他使用nice-select.js作为下拉菜单。我将它导入我的index.html并执行了这个:

$(document).ready(function(e){
    $(".drop").niceSelect();
}

当它加载到第一页时它工作正常。但是在单击指向不同组件的菜单项时,js 不会在此处启动,并且设计不会针对该组件。

现在如何在中使用此$功能ComponentdidMountMethod()

我已经使用 npm install jquery --save 安装了 jquery 并尝试使用它但出现错误niceSelect is not a function

任何人都可以在这方面提供帮助。

提前致谢。

import React, { Component } from 'react';
import{Link} from 'react-router-dom';
import $ from 'jquery';

$(".drop").niceSelect();

这给出了一个错误 nice select is not a function。

4

1 回答 1

0

我也有同样的问题。我以这种方式解决了这个问题。

import React from 'react';
import {Link} from 'react-router-dom';
import $ from 'jquery';
import '../../css/nice-select.css';
import '../../js/nice';

class Name extends React.Component{
render(){
    $(document).ready(function() {
        $('.drop').niceSelect();
      });
    return (
        <select class="drop">...</select>
    );
 }
}

export default Name;
于 2020-10-25T17:43:25.787 回答