Skip to content
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

tsx 环境下 v-model不生效 #589

Closed
CharlieLau opened this issue Nov 12, 2020 · 4 comments
Closed

tsx 环境下 v-model不生效 #589

CharlieLau opened this issue Nov 12, 2020 · 4 comments

Comments

@CharlieLau
Copy link

求助大佬🧍‍♂️
在tsx 环境下 v-model 不生效

import { defineComponent, ref } from 'vue-demi'

export const Hello2Component = defineComponent({
  props: {
    a: String
  },
  setup(props) {
    const text = ref(props.a)
    return () => (
      <div>
        {/* 不生效 */}
        <input v-model={text.value} ></input>
        {/* 生效 */}
        <input value={text.value} on-input={e => text.value = e.target.value}></input>
      </div>
    )
  }
})

.babelrc 配置

{
  "presets": [
    "@babel/env",
    "@babel/preset-typescript",
    [
      "@vue/babel-preset-jsx",
      {
        "vModel": false,
        "compositionAPI": true
      }
    ]
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    "@babel/proposal-class-properties",
    "@babel/proposal-object-rest-spread"
  ]
}
@danielroe
Copy link
Member

@CharlieLau Shouldn't that be vModel? And haven't you disabled the vModel directive in .babelrc? (See more info.)

I don't think this is an issue with the Composition API plugin.

@CharlieLau
Copy link
Author

�readme tell me can follow this: https://github.com/vuejs/jsx/tree/dev/packages/babel-preset-jsx#usage

when i set
.babelrc

// "vModel": false,
  "plugins": [
    "module:@vue/babel-sugar-v-model",
    ...
]

hello.tsx

...
export const Hello2Component = defineComponent({
  props: {
    a: String
  },
  setup(props) {
    const text = ref(props.a)
    return () => (
      <div>
        <input vModel={text.value} ></input>
      </div>
    )
  }
})

but, errors:
[!] (plugin babel) TypeError: /packages/kabuta-mtd/src/hello.tsx: Cannot read property 'body' of undefined
@nibfe/xx-package: src/hello.tsx
@nibfe/xx-package: TypeError: /packages/kabuta-mtd/src/hello.tsx: Cannot read property 'body' of undefined
@nibfe/xx-package: at MemberExpression (
/node_modules/@vue/babel-sugar-composition-api-render-instance/dist/plugin.js:1:1179)
@nibfe/xx-package: at NodePath._call (
/node_modules/@babel/traverse/lib/path/context.js:55:20)
@nibfe/xx-package: at NodePath.call (/node_modules/@babel/traverse/lib/path/context.js:42:17)
@nibfe/xx-package: at NodePath.visit (
/node_modules/@babel/traverse/lib/path/context.js:92:31)
@nibfe/xx-package: at TraversalContext.visitQueue (/node_modules/@babel/traverse/lib/context.js:112:16)
@nibfe/xx-package: at TraversalContext.visitSingle (
/node_modules/@babel/traverse/lib/context.js:84:19)
@nibfe/xx-package: at TraversalContext.visit (*/node_modules/@babel/traverse/lib/context.js:140:19)

@LemonAppleMo
Copy link

use this -> https://github.com/luwanquan/babel-preset-vca-jsx

@antfu
Copy link
Member

antfu commented Nov 13, 2020

Keep track on vuejs/jsx-vue2#169 instead. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants