Home >Web Front-end >JS Tutorial >Detailed explanation of the use of Mixins.js in React.js

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

php中世界最好的语言
php中世界最好的语言Original
2018-03-13 14:54:012365browse

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

Define a mixins.js file

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

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

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

is the same as setting the attribute type

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

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

MixinLog.log();

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!

Statement:
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
Previous article:React.js propsNext article:React.js props