Open avxkim opened 3 years ago
I have the same question:
Try `npm install @types/vue-json-excel` if it exists or add a new declaration (.d.ts) file containing `declare module 'vue-json-excel';`
1 | import Vue from "vue";
> 2 | import JsonExcel from "vue-json-excel";
| ^^^^^^^^^^^^^^^^
but
npm install @types/vue-json-excel
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@types%2fvue-json-excel - Not found
npm ERR! 404
npm ERR! 404 '@types/vue-json-excel@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/daniel/.npm/_logs/2021-01-14T13_16_17_501Z-debug.log
This worked for me.
In src/main.ts
import JsonExcel from "vue-json-excel";
Vue.component("downloadExcel", JsonExcel);
In tsconfig.json
...
"paths": {
"@/*": [
"src/*"
],
"*": [
"*",
"types/*"
]
},
...
In src/shims-vue.d.ts
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
declare var JsonExcel: any;
declare module "vue-json-excel" {
export = JsonExcel;
}
Finally, I created a src/types/vue-json-excel.d.ts
with
import Vue from "vue";
declare module 'vue-json-excel' {
export default class JsonExcel extends Vue {
}
}
There may be some missing interfaces in the .d.ts
but it works with:
<download-excel :data="items">
Download
<v-icon>mdi-file-excel</v-icon>
</download-excel>
Do you plan to add typings?