我安装了一个新的 Vue 3,其中包含 vue-cli 和 typescript。
一切都在运行
但是当我添加一个https://vue-select.org/ https://vue-select.org/包裹
我在浏览器控制台上收到此错误
Uncaught (in promise) TypeError: this.$on is not a function
at Proxy.created (vue-select.js?4a7a:1)
at callWithErrorHandling (runtime-core.esm-bundler.js?5c40:155)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js?5c40:164)
at callHook (runtime-core.esm-bundler.js?5c40:3182)
at applyOptions (runtime-core.esm-bundler.js?5c40:3109)
at finishComponentSetup (runtime-core.esm-bundler.js?5c40:7265)
at setupStatefulComponent (runtime-core.esm-bundler.js?5c40:7190)
at setupComponent (runtime-core.esm-bundler.js?5c40:7117)
at mountComponent (runtime-core.esm-bundler.js?5c40:5115)
at processComponent (runtime-core.esm-bundler.js?5c40:5090)
简单的例子
Home.vue
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<vSelect :options="[{label: 'Canada', code: 'ca'}]"></vSelect>
</div>
</template>
<script lang="ts">
import { Options, Vue } from 'vue-class-component';
import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
import vSelect from 'vue-select';
@Options({
components: {
HelloWorld,
vSelect
},
})
export default class Home extends Vue {}
</script>
我认为这个问题与Vue3无关。它与打字稿有关。只需添加这个包即可@types/vue-select
。该包包含以下类型的定义vue-select
。另外,如果您的捆绑程序使用 webpack,请不要忘记添加此包@types/webpack-env
。它包含 webpack 的类型定义。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)