wechat-miniprogram / wechat-miniprogram/computed
computed 属性第一次会返回 null
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 696
- Forks
- 61
- PR merge metrics
- No merged PRs in 30d
Description
我按照如下方式使用 computed,但是第一次 state 会返回 null,导致我的组件警告提示,说传入了一个 null,但是需要 string
data: {
isConnected: true,
},
computed: {
text({ isConnected }) {
return isConnected ? "网络正常" : "网络异常";
},
state({ isConnected }) {
return isConnected ? "success" : "error";
},
},
lifetimes: {
attached() {
wx.onNetworkStatusChange((res) => {
this.setData({
isConnected: res.isConnected,
});
});
},
},
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported computed setup with the TypeScript example and inspect when the computed state value is initialized. Confirm that the first value is a string rather than null and that the component warning no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100