typescript - Vue 3 - Composition Api - Typescript -> 发射类型
问题描述
我从 VUE 3 和第一次使用 Typescript 的组合 api 开始。我有如下设置方法:
setup(props: { widgetType: string; displayType: string; trigger: number }, { emit })
现在,当我构建此文件时,我收到错误“绑定元素'emit'隐含地具有'any'类型。”。我不知道如何解决这个问题。我尝试了来自网络的不同解决方案,但没有任何效果。有谁能够帮我?问候克里斯
解决方案
您需要使用该defineComponent
方法定义您的组件并将正确的类型应用于道具。如果您使用的是单个文件组件,它看起来像这样
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
props: {
widgetType: {
type: String,
required: true
},
displayType: {
type: String,
required: true
},
trigger: {
type: number,
required: true
}
},
setup(props, { emit }) {
// Rest of your setup code here
}
});
</script>
推荐阅读
- apache - 配置 CSP 和 iframe 有什么问题
- angular - 在 angular.json 中扁平化资产
- python - 是否可以在一定时间后停止 Python 中的 exec 或 eval ?
- python - 如何使用 python 从 Maya 内部搜索外部文件结构
- python - 在 Pandas 中将特定列的行除以 date+n
- java - 在Java中的循环内替换字符串中特定位置的字符
- javascript - 根据搜索查询更改远程 URL
- c++ - 在编译时获取文件字符串
- python - keras多层LSTM模型的股价预测收敛到一个恒定值
- amazon-web-services - 如何加快 AWS Fargate 上的部署?