Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the use of Mixins.js in React.js

php中世界最好的语言
Release: 2018-03-13 14:54:01
Original
2326 people have browsed it

This time I will bring you a detailed explanation of the use of Mixins.js in React.js. What are the precautions for using Mixins.js in React.js? Here are the actual cases, let’s take a look.

First npm import react-mixin

npm install --save react-mixin@2
Copy after login

Define a mixins.js file

const MixinLog = {  //他和普通组件一样,也是有生命周期的
  componentWillMount() {      console.log('MixinLog--componentWillMount');
  },  // 定一个公共方法
  log() {      console.log('abcdefg.......');
  }
}export default MixinLog
Copy after login

Where to use, first import react-mixin and your own defined mixins

import ReactMixin from 'react-mixin';import MixinLog from './mixins';
Copy after login

is the same as setting the attribute type

ReactMixin(组件名字.prototype, MixinLog);
Copy after login

Call it where you want to use it: call the log() method

MixinLog.log();
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please Pay attention to other related articles on php Chinese website!

Recommended reading:

Vue.js-vuex (state management)

Vue.js uses transition animation to create routing jump animations

Route naming and named views of Vue.js

The above is the detailed content of Detailed explanation of the use of Mixins.js in React.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template