簡體   English   中英

react-materialize $(…).tabs不是函數

[英]react-materialize $(…).tabs is not a function

無法從物化調用.tabs()函數,所有內容看起來.tabs()導入,並且以正確的順序導入了物化.tabs() ,然后是jQuery,然后是物化.tabs() jQuery函數工作正常,實現-不要

$(...)。tabs不是函數

問題應該在導入中的某個地方,但我無法理解是什么問題。

index.html

 <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <!-- Import materialize.css -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css" rel="stylesheet" >
    <title>Title</title>
  </head>
  <body>  

    <div id="root"></div>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/js/materialize.min.js"></script>

  </body>

我從那里打電話的組件

import React,{Component} from 'react';
import {Tab,Tabs} from 'react-materialize'
export default class Tab1 extends Component{

  next(){
    let $ = require('jquery');

    $('ul.tabs').tabs('select_tab','tab_01');
    // alert();
  }

  render(){
    return(
      <div className="swipeTab" >
        <a onClick={()=> this.next()} className="waves-effect btn onasTabTrigger hoverable">Button</a>
      </div>

    );
  }
}

此Tab1組件只是作為父級中選項卡的內容放置的

<Tabs className='tabs z-depth-1' tabOptions={{swipeable: true }} onChange={() => console.log(this)}>
  <Tab title="tab1" active >
    <Tab1 />
  </Tab>
  <Tab title="tab2" >
    <Tab2/>
  </Tab>
</Tabs>

將選項卡初始化放在componentDidMount

next通話的click事件中刪除初始化。

//onClick={()=> this.next()} remove it

零件 :

let $ = require('jquery');

export default class Tab1 extends Component{


        componentDidMount(){            
            //initialisation goes here.
          $('ul.tabs').tabs('select_tab','tab_01');
        }

        render(){  
            return(
              <div className="swipeTab" >                   
                     <a className="waves-effect btn onasTabTrigger hoverable">Button</a>  
                </div>
            );
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM