相关疑难解决方法(0)

未捕获的类型错误:emit 不是 vue3 中的函数

当我在 vue 3 设置代码块中编写此代码以获取遵循此答案的输入值时,这是代码的一部分:

import { defineComponent } from "vue";
import { defineProps, defineEmits } from 'vue'

export default defineComponent({
  setup() {
    const props = defineProps({
      modelValue: String
    })
    const emit = defineEmits(['update:modelValue'])
    function updateValue(value: any) {
      emit('update:modelValue', value)
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序运行时显示错误:

option.js:17388 Uncaught TypeError: emit is not a function
    at Proxy.updateValue (option.js:17388:13)
    at onInput._cache.<computed>._cache.<computed> (option.js:17428:78)
    at callWithErrorHandling (option.js:7359:22)
    at callWithAsyncErrorHandling (option.js:7368:21)
    at HTMLInputElement.invoker (option.js:15384:90)
Run Code Online (Sandbox Code Playgroud)

我已经定义了emit,为什么仍然告诉我emit不是一个函数?这是我的 vue3 组件的完整代码:

<template>
  <div id="app">
    <div id="wrap">
      <label> 
        {{ username }}
      </label> …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js vuejs3 vue-composition-api vue-script-setup

7
推荐指数
1
解决办法
2万
查看次数