-
Notifications
You must be signed in to change notification settings - Fork 113
Component 不能往 this 上加自定义属性 #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
官方是不支持的,但是你可以在构造器前声明一个对象,在那里存储。 |
我的意思是,你在 Component() 之前声明一个对象就可以了......
1728317209 <[email protected]> 于 2020年5月30日周六 11:18写道:
… 官方是不支持的,但是你可以在构造器前声明一个对象,在那里存储。
🙏
在 global.d.ts 里这样写👇,我试了下是可以的
[image: image]
<https://user-images.githubusercontent.com/39460401/83318397-09ebc900-a267-11ea-8d91-4979dcbbc8ff.png>
但是会有 lib.wx.component.d.ts(25, 14): 'Instance' was also declared here.
这样标识符重复的报错,这样没关系吗?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#133 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AH6FX6XETVLX6MS4AEEQQALRUB3JZANCNFSM4NOFAVAQ>
.
|
Component 是不能像 Page 一样在构造参数顶层加自定义参数的,就 Component({
test: 1,
methods: {
fn() {
this.test // undefined
}
}
}) 要挂自定义参数只能直接 |
我们项目里面,一般渲染层用不到的数据,都是 this.xxx 或 this.state.xxx,渲染层用到的数据,才会放到 data 里 |
我的习惯是在第一行 const state = {} 然后再注册 Component。一定要用 this么?
|
在第一行 const state = {},这个 state 是所有组件公共的 state 如果 目前就想到这一种情况... |
那我正好来推销一下 纯数据字段 不过话说回来,往自定义组件实例上挂属性既然是可以的,应该还是得想办法支持。下个版本看看加一个泛型 mixin 到实例上解决这个问题吧 |
2.8.2劝退了😂 |
感谢🙏 |
我们基础库还是 1.9.4 😂 |
我基础库2.5.2我觉得已经很高了 |
2.8.3 以上都已经 98% 了呀😂 |
暂且先关闭了,如果有问题再重新打开吧 |
请问如何给properties中的参数提供默认值呢?我想用比如 |
这是啥解决方案啊,本来 IData, IProperty, IMethod 是能自动推导的,现在为了声明 ICustomInstanceProperty,前面几个泛型也得声明了,你们弄了这个方案后自己实际用过吗?不觉得别扭吗。。。 |
确实是很别扭,主要是基于这些原因:
目前这套框架接口因为设计的时间比较早,那时候 TS 相对来说不像现在这么流行,因此接口对 TS 并不太友好;现在这套方案是考虑以上限制下能解决问题的一种方案,但是由于我水平有限,确实很别扭;如果有更好的方案也欢迎提出,可以再改进这份定义 我们这两年重新设计的新版框架接口中有考虑这个用法了(wechat-miniprogram/glass-easel#70),这份定义后面也会补上链式调用的支持(#315) |
Page 可以往 this 上加自定义属性,Component 不可以,能支持吗?
The text was updated successfully, but these errors were encountered: