Skip to content

Commit 6aa7278

Browse files
committed
fix: add fallback when generate state key fails
1 parent 8b4b104 commit 6aa7278

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/vue-generator/src/generator/vue/sfc/generateAttribute.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,12 @@ export const handleObjBindAttrHook = (schemaData, globalHooks, config) => {
589589
addSuccess = globalHooks.addState(stateKey, `${stateKey}:${res}`)
590590
}
591591

592-
attributes.push(`:${key}="state.${stateKey}"`)
592+
if (addSuccess) {
593+
attributes.push(`:${key}="state.${stateKey}"`)
594+
} else {
595+
// state 注册失败,回退到内联绑定
596+
attributes.push(`:${key}="${res.replaceAll(/"/g, '"')}"`)
597+
}
593598
} else {
594599
attributes.push(isJSX ? `${key}={${res}}` : `:${key}="${res.replaceAll(/"/g, '"')}"`)
595600
}

0 commit comments

Comments
 (0)