const c = defineModel('count')
const toString = defineModel('toString', { type: Function })
</script>
- `,
- { defineModel: true }
+ `
)
assertCode(content)
expect(content).toMatch('props: {')
defineEmits(['change'])
const count = defineModel({ default: 0 })
</script>
- `,
- { defineModel: true }
+ `
)
assertCode(content)
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels({ foo: String }`)
defineProps(['foo', 'bar'])
const count = defineModel('count')
</script>
- `,
- { defineModel: true }
+ `
)
assertCode(content)
expect(content).toMatch(`props: /*#__PURE__*/_mergeModels(['foo', 'bar'], {
const local = true
const hoist = defineModel('hoist', { local })
- </script>`,
- { defineModel: true }
+ </script>`
)
assertCode(content)
expect(content).toMatch(`_useModel(__props, "modelValue", { local: true })`)
const disabled = defineModel<number>('disabled', { required: false })
const any = defineModel<any | boolean>('any')
</script>
- `,
- { defineModel: true }
+ `
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
const optional = defineModel<string>('optional', { required: false })
</script>
`,
- { defineModel: true, isProd: true }
+ { isProd: true }
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: Boolean }')
* @default true
*/
hoistStatic?: boolean
- /**
- * (**Experimental**) Enable macro `defineModel`
- * @default false
- */
- defineModel?: boolean
/**
* (**Experimental**) Enable reactive destructure for `defineProps`
* @default false
toRuntimeTypeString
} from './utils'
import { BindingTypes, unwrapTSNode } from '@vue/compiler-dom'
-import { warnOnce } from '../warn'
export const DEFINE_MODEL = 'defineModel'
return false
}
- if (!ctx.options.defineModel) {
- warnOnce(
- `defineModel() is an experimental feature and disabled by default.\n` +
- `To enable it, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
- )
- return false
- }
-
- warnOnce(
- `This project is using defineModel(), which is an experimental ` +
- `feature. It may receive breaking changes or be removed in the future, so ` +
- `use at your own risk.\n` +
- `To stay updated, follow the RFC at https://github.com/vuejs/rfcs/discussions/503.`
- )
-
ctx.hasDefineModelCall = true
const type =
}
/**
- * (**Experimental**) Vue `<script setup>` compiler macro for declaring a
+ * Vue `<script setup>` compiler macro for declaring a
* two-way binding prop that can be consumed via `v-model` from the parent
* component. This will declare a prop with the same name and a corresponding
* `update:propName` event.
script: {
inlineTemplate: !useDevMode.value,
isProd: !useDevMode.value,
- propsDestructure: true,
- defineModel: true
+ propsDestructure: true
},
style: {
isProd: !useDevMode.value
plugins: [
vue({
script: {
- defineModel: true,
fs: {
fileExists: fs.existsSync,
readFile: file => fs.readFileSync(file, 'utf-8')