Mixins

The developer may implement multiple custom components which may have common logics to be processed. The Mini Program provides the mixins to meet the requirement.
Sample code:

copy
// /minxins/lifecylce.js
export default {
  onInit(){}, 
  deriveDataFromProps(nextProps){},
  didMount(){},
  didUpdate(prevProps,prevData){},
  didUnmount(){},
};
copy
// /pages/components/xx/index.js
import lifecylce from '../../minxins/lifecylce';
const initialState = {
  data: {
    y: 2
  },
};
const defaultProps = {
  props: {
    a: 3,
  },
};
const methods = {
  methods: {
    onTapHandler() {},
  },
}
Component({
  mixins: [
    lifecylce,
    initialState,
    defaultProps,
    methods
  ],
  data: {
    x: 1,
  },
});