自定义组件methods为何不能支持非函数的事件
发布于 4 年前 作者 yang59 15162 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

1.小程序组件里的method只能是函数类型,其他会被过滤掉

例如,

const Class testClass {
}
 
const test = new testClass()
 
{
   methods: {
     test,
   }
}

这样是无效的

也不能够是

{
 methods:{
    test: {}
 }
}

为什么要过滤,而页面则则不影响

2.小程序组件里option除了一定指定的key,其他都会被过滤

例如

const option = {

   name: "test",

  methods: {

  }

}

这个name就会过滤掉

  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo
1 回复

设计如此,所有官方定义段必须符合要求。如果你需要自定义定义段的话,可以走自定义组件扩展将其转化成官方定义段:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html

回到顶部