混入

参考 Vue 官方文档

示例


  • test.js
  1. export default {
  2. data: {
  3. mixin: 'MixinText'
  4. },
  5. methods: {
  6. mixintap () {
  7. this.mixin = 'MixinText' + (Math.random() + '').substring(3, 7);
  8. console.log('mixin method tap');
  9. },
  10. tap () {
  11. console.log('tap in mixin');
  12. }
  13. },
  14. created () {
  15. console.log('created in mixin');
  16. }
  17. }
  • pageA.wpy
  1. <template>
  2. <div @click="mixintap">{{ mixin }}</div>
  3. </template>
  4. <script>
  5. import wepy from '@wepy/core'
  6. import testMixin from '../mixins/test.js'
  7. wepy.page({
  8. mixins: [ testMixin ]
  9. })
  10. </script>