Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

vue使用ts后注册插件的问题

我想在全局添加一个组件,就使用了Vue.use的方法注册一个插件,在引入ts后,便报了这一句错误,求解怎么解决

index.ts

import infoList from './components/public/info.vue'
const Components = {
    infoList,
}
const installer = {
    install(Vue:any,opt:any)?{
        Object.keys(Components).forEach((name:any) => {
            Vue.component(name, Components[name]) // X
        })
    }
}

export default installer

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
interface Vue{}

interface VueConstructor<T> {
    instance:T;
}

let inforList:VueConstructor<String>={
    instance:'TEST',
}

const Components:{[key:string]:VueConstructor<String>} = {
    infoList:inforList
}

const installer = {
    install(Vue:any,opt:any) {
        Object.keys(Components).forEach((name:any) => {
            Vue.component(name, Components[name]) // X
        });
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...