page.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { VantComponent } from '../components/vant-ui/common/component'
  2. export function VueLikePage (filters, options) {
  3. if (typeof filters === 'function') {
  4. filters = [filters]
  5. } else if (!Array.isArray(filters)) {
  6. options = filters
  7. filters = []
  8. }
  9. if (filters.length > 0) {
  10. filters.forEach(filter => options = filter(options))
  11. }
  12. options.mixins = options.mixins || []
  13. return VantComponent(options)
  14. }
  15. /**
  16. * 给页面加上生命周期钩子函数
  17. * @param {Object} options 页面选项
  18. * @param {String} method 生命周期key
  19. * @param {Function} fn 钩子函数
  20. */
  21. function hookPageLifeTimeMethod (options, method, fn) {
  22. let _method
  23. if (options[method]) {
  24. _method = options[method]
  25. } else if (options.methods && options.methods[method]) {
  26. _method = options.methods[method]
  27. }
  28. if (!options.methods) {
  29. options.methods = {}
  30. }
  31. options[method] = options.methods[method] = function (args) {
  32. if (fn.call(this, args) === false) {
  33. return
  34. }
  35. if (typeof _method === 'function') {
  36. _method.call(this, args)
  37. }
  38. }
  39. return options
  40. }