Skip to content

Commit

Permalink
fix(weapp): 修复在render中通过return来中断代码执行可能会造成state丢失的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Simbachen committed Sep 3, 2018
1 parent 2920f33 commit 5402dff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/taro-weapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function createComponent (ComponentClass, isPage) {
const componentInstance = new ComponentClass(componentProps)
componentInstance._constructor && componentInstance._constructor(componentProps)
try {
componentInstance.state = componentInstance._createData()
componentInstance.state = componentInstance._createData() || componentInstance.state
} catch (err) {
const errLine = err.stack.toString().split(/\n/)[2] || ''
console.warn(`[Taro warn]
Expand Down
3 changes: 2 additions & 1 deletion packages/taro-weapp/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function doUpdate (component) {
const { state, props = {} } = component
let data = state || {}
if (component._createData) {
data = component._createData(state, props)
// 返回null或undefined则保持不变
data = component._createData(state, props) || data
}
let privatePropKeyVal = component.$scope.data[privatePropKeyName] || false

Expand Down

0 comments on commit 5402dff

Please sign in to comment.