Home > Article > Web Front-end > Detailed explanation of the use of Mixins.js in React.js
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-mixinnpm install --save react-mixin@2Define a mixins.js file
const MixinLog = { //他和普通组件一样,也是有生命周期的 componentWillMount() { console.log('MixinLog--componentWillMount'); }, // 定一个公共方法 log() { console.log('abcdefg.......'); } }export default MixinLogWhere 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!