Skip to content

Commit

Permalink
fix(vue3): codegen v-model on simple reactive variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Feb 18, 2023
1 parent b158b22 commit 5701116
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/vue3/cypress/integration/codegen-vue3.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ describe('Codegen (Vue 3)', () => {
<HstText
v-model:foo="state.count"
v-model:my-prop.number="state.count"
/>`)
/>
<HstText v-model="value" />`)
})

it('custom-directive', () => {
Expand Down
7 changes: 6 additions & 1 deletion examples/vue3/src/components/CodeGen.story.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { defineComponent } from 'vue'
import { defineComponent, ref } from 'vue'
export default defineComponent({
directives: {
Expand Down Expand Up @@ -27,6 +27,8 @@ function initState () {
function onClick (event) {
console.log(event)
}
const value = ref('Foo')
</script>

<template>
Expand Down Expand Up @@ -151,6 +153,9 @@ function onClick (event) {
v-model:foo="state.count"
v-model:my-prop.number="state.count"
/>
<HstText
v-model="value"
/>
</template>
</Variant>
<Variant
Expand Down
2 changes: 1 addition & 1 deletion packages/histoire-plugin-vue/src/client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function printVNode (vnode: VNode, propsOverrides: Record<string, any> = n
// v-model on component
const vmodelListeners = [`onUpdate:${prop}`, `onUpdate:${camelCase(prop)}`]
// @ts-ignore
const vmodelListener = vmodelListeners.find(key => vnode.dynamicProps?.includes(key))
const vmodelListener = vmodelListeners.find(key => vnode.dynamicProps?.includes(key) || key in vnode.props)
if (directive === ':' && vmodelListener) {
// Listener
skipProps.push(vmodelListener)
Expand Down

0 comments on commit 5701116

Please sign in to comment.