ソースを参照

fix(compiler-vapor): register event for v-model

三咲智子 Kevin Deng 2 年 前
コミット
88123e56d0

+ 12 - 12
packages/compiler-vapor/__tests__/transforms/__snapshots__/vModel.spec.ts.snap

@@ -7,7 +7,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model, void 0, { lazy: true }]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -19,7 +19,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model, void 0, { number: true }]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -31,7 +31,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model, void 0, { trim: true }]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -43,7 +43,7 @@ const t0 = _template("<input type=\\"checkbox\\">")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelCheckbox, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -55,7 +55,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelDynamic, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -67,7 +67,7 @@ const t0 = _template("<input type=\\"radio\\">")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelRadio, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -79,7 +79,7 @@ const t0 = _template("<input type=\\"text\\">")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -91,7 +91,7 @@ const t0 = _template("<select></select>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelSelect, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -103,7 +103,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -115,7 +115,7 @@ const t0 = _template("<textarea></textarea>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelText, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;
@@ -127,7 +127,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelDynamic, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   _renderEffect(() => _setDynamicProps(n1, _ctx.obj))
   return n1
 }"
@@ -140,7 +140,7 @@ const t0 = _template("<input>")
 export function render(_ctx) {
   const n1 = t0()
   _withDirectives(n1, [[_vModelDynamic, () => _ctx.model]])
-  _on(n1, "update:modelValue", $event => (_ctx.model = $event))
+  _on(n1, "update:modelValue", () => $event => (_ctx.model = $event))
   return n1
 }"
 `;

+ 1 - 1
packages/compiler-vapor/src/generators/modelValue.ts

@@ -18,7 +18,7 @@ export function genSetModelValue(
     ? [JSON.stringify(`update:${camelize(oper.key.content)}`)]
     : ['`update:${', ...genExpression(oper.key, context), '}`']
   const handler = [
-    (isTS ? `($event: any)` : `$event`) + ' => (',
+    `() => ${isTS ? `($event: any)` : `$event`} => (`,
     ...genExpression(oper.value, context, '$event'),
     ')',
   ]