wxpage icon indicating copy to clipboard operation
wxpage copied to clipboard

不同page 可能有相同函数功能

Open GoToBoy opened this issue 5 years ago • 3 comments

小程序页面简单,不同页面可能会有部分相同的函数功能和部分相同的html(类似小程序template),单纯封装成组件,又过度设计和时间不允许,是不是可以提供一个接口暴露出page某个函数可以被其他page使用~

我现在采用的办法是提取到一个公共的common文件中,需要用到再export出来,或者可以探讨下提取到common才是合理的,再去做暴露的功能也是过度设计!!

谢谢

GoToBoy avatar Jan 13 '19 00:01 GoToBoy

通过 extendPageBefore/extendPageAfter 可以扩展任意指定页面可用的实例方法

switer avatar Jan 13 '19 05:01 switer

通过 extendPageBefore/extendPageAfter 可以扩展任意指定页面可用的实例方法

能否给个demo?

GoToBoy avatar Feb 21 '19 09:02 GoToBoy

A({
  config: {
    extendPageBefore: function (def, { fns }) {
      def.someReusedMethod = function () {
          // TODO
      }
    }
  }
});

switer avatar Feb 21 '19 11:02 switer